This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » ajax response always whole page
ajax response always whole page [message #102372] Mon, 12 July 2010 17:03 Go to next message
Aginor404  is currently offline Aginor404
Messages: 6
Registered: June 2010
Location: Germany
Junior Member
Hi there again!

As always please link me if this was answered before. I did a quick search though and didn't find anything like that, so here is my question:


Situation:
I use a button_to_remote call to do some ajax.

This is the part of my indexSuccess.php
echo button_to_remote(__('Get my text!', NULL, 'evlist'), array(
           "url"=>"events/getmytext",
           "complete"=>"alert('here the response: '+request.responseText+' yay!');"
               )
         );      		


So as you see I just want to get a String from the server and alert it.


So in my actions.class php there is
public function executeGetmytext()
{
$this->output = "foo bar text";
}




and my getmytextSuccess.php looks like this
<?php use_helper('Javascript') ?>
<?php  echo $output ?>




My problem is: the request.responseText consists of my whole index.php page instead of what I want to have.

I already tried to mess with the headers, render a partial instead of a templateaand to deactivate the template with has_layout: off in the view.yml

The result is always the same. Now I think it ignores all I'm doing...

All I want is that I'm able to get some response (a string) and use JAvascript to write it into a DOM element, to use it later.



What am I doing wrong?
Thanks in advance
-Aginor
Re: ajax response always whole page [message #102398 is a reply to message #102372 ] Tue, 13 July 2010 09:05 Go to previous messageGo to next message
hasc  is currently offline hasc
Messages: 195
Registered: October 2007
Senior Member
Hi,

you have to return a text/partial/component within the action. If you return a template together with the layout you will get the complete page returned.

So within the function executeGetmytext() you have to do something like:
return $this->renderText('Foo'); // returns 'Foo'
// or
return $this->renderPartial('path/to/partial') // returns a partial
// or
return $this->renderComponent('module', 'action'); // returns a component


Regards,
hasc
Re: ajax response always whole page [message #102407 is a reply to message #102398 ] Tue, 13 July 2010 11:12 Go to previous messageGo to next message
Aginor404  is currently offline Aginor404
Messages: 6
Registered: June 2010
Location: Germany
Junior Member
Thanks for your answer.

I tried what you wrote (return $this->renderText('mystring');) and also found out that I'm doing almost the exact same thing in another module, ...but it doesn't work.

I always get the whole index.php with all the layout and stuff, and mystring isn't even part of that.

I don't even have a template now (I deleted it just to see what happens) and the view.yml says "has_layout: off"


Any ideas what that could be? Probably a configuration problem?
-Aginor

[Updated on: Tue, 13 July 2010 11:12]

Re: ajax response always whole page [message #102408 is a reply to message #102372 ] Tue, 13 July 2010 11:23 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Did you clear your cache?

As well as resetting the layout in view.yml, you can do $this->setLayout(false) in your action instead.


Remember Palestine
Re: ajax response always whole page [message #102410 is a reply to message #102407 ] Tue, 13 July 2010 11:41 Go to previous messageGo to next message
hasc  is currently offline hasc
Messages: 195
Registered: October 2007
Senior Member
Hi,

you have to verify that the correct module and action is invoked by the request (routing). Currently another module/action is obviously envoked. Maybe also some security settings are the reason that the wrong action is invoked.

regards,
hasc
Re: ajax response always whole page [message #102411 is a reply to message #102410 ] Tue, 13 July 2010 11:49 Go to previous messageGo to next message
Aginor404  is currently offline Aginor404
Messages: 6
Registered: June 2010
Location: Germany
Junior Member
Thanks again, I will check that.

Yes, I cleared my cache, now checking routing and stuff.
Re: ajax response always whole page [message #102422 is a reply to message #102372 ] Tue, 13 July 2010 14:21 Go to previous message
Aginor404  is currently offline Aginor404
Messages: 6
Registered: June 2010
Location: Germany
Junior Member
Sorry for the double post.

I solved my problem... kinda.

You were right with the routing or the security, I think. If the action is part of another module everything works perfectly.
I moved the action to another module, that's all.
I'm happy with that because I realized it fits better in that other module anyway, so no harm done.

Ok, I'm not completely happy with it because I don't like it when something works and I don't know why. I'll report back when I've found out what's happening.



Thanks a lot for your support!
-Aginor
Previous Topic:Retrieving old user password when editing a user in backend
Next Topic:ERROR:: insert two records to the embeded form table
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software