help with ajax.Request

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lapith
Forum Newbie
Posts: 11
Joined: Fri Jul 27, 2007 4:37 pm

help with ajax.Request

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
lapith
Forum Newbie
Posts: 11
Joined: Fri Jul 27, 2007 4:37 pm

Post 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().
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post 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.
Post Reply