Re: Parsing AJAX post data -- The Way

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stut wrote:
> M5 wrote:
>> Just wondering what smart people do for parsing data sent by the
>> Javascript XMLHTTP object--e.g., http.send("post",url,true)...
>>
>> In a normal form submit, the $_POST global nicely allocates form
>> elements as array elements automatically. But with the AJAX way, the
>> data get stuffed inside $HTTP_RAW_POST_DATA as a string, thereby
>> making extraction more tedious.
> 
> What format is the data you are posting in? If it's in the usual format,
> PHP should parse it for you. An AJAX (hate that acronym) post request is
> no different to a normal post, unless you are not posting in the form
> format (var1=val2&var2=val2).

Yes, just to elaborate, consider the following (simple AJAX post (using
prototype.js as it's great!).


function SendRemote(action)
{
  new Ajax.Request('backend.php', { parameters: 'submit='+action });
}

This sends a simple form POSTED to the server with one form element
(named "submit") which will be available to the server as $_POST['submit'].

If you want to add more, just use the & as Stut suggests, e.g.:

function SendRemote(action)
{
  new Ajax.Request('backend.php', { parameters:
'submit='+action+'&var2=xxx' });
}

etc.

HTH

Col.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux