Page 1 of 1

help with ajax.Request

Posted: Thu Aug 09, 2007 11:15 am
by lapith
Okay. I know that this has to do with Prototype, which not everyone uses, but any help would be greatly appreciated.

I am currently using an ajax.request to call a php file so that I can update an object that is stored as a Session variable. To do this call I am using this code.

var query_string = "scripts/update_widget_action.php?service_id=" + qsParm['service_id'] + "&" + value;

new Ajax.Request(query_string, { asynchronous:true, method:'post', onSuccess:loadit() });

This works great. However once I get to the update_widget_action.php and I try to do a print_r($_SESSION), it prints an empty array. To solve this I tried to put in a session_start(); which then throws an error stating that the headers have already been sent. Has anyone ran into this before?

Posted: Thu Aug 09, 2007 11:18 am
by RobertGonzalez
You can't start a session after output has been sent to the browser (output is sent after response headers are sent, so trying to send more headers after they have left the building is a no no).

Does the protoype community have a forum?

Posted: Thu Aug 09, 2007 11:25 am
by lapith
I have not been able to find a forum for prototype... they only seem to have an IRC channe, which is great unless your work is blocking IRC.

Thank you for your fast response. I am a bit new to this, so I am unsure of exactly where I would be sending a response to the browser. Since it is AJAX it doesn't seem like that is so "cut-n-dry" once I make that call to the update_widget_action.php, the first (and only) thing that I do is a session_start().

Posted: Thu Aug 09, 2007 12:09 pm
by TheMoose
Did you put the session_start() at the top of the file, or midway through the code? Try putting it at the top if you haven't already and see what that returns.