Skip to content Skip to sidebar Skip to footer

Ajax Serialize; Cant 'read' Variables In PHP

I have this code: var data_string = $('form#frm').serialize(); $.ajax({ type: 'POST', url: '/send.php', data: data_string, su

Solution 1:

According to the .serialize() documentation:

Note: Only "successful controls" are serialized to the string. No submit button value is serialized since the form was not submitted using a button. For a form element's value to be included in the serialized string, the element must have a name attribute. Data from file select elements is not serialized.

Did you check all of this? Have you tried alerting data_string?


Solution 2:

Have you tested the data_string? Try doing an alert on it first to check it has data in it!

var data_string = $('#frm').serialize();
alert(data_string);

Solution 3:

If you are trying to pass data to the javascript function then why not just use json (http://json.org/) for this, as it is designed to serialize and there are numerous options for most languages, so you don't have to reinvent the wheel.

Ultimately you can spend time working on how to get serialize to work, but your time may be more productive if you consider making a change.


Solution 4:

Try print_r($_POST) instead to see if your $_POST vars are posted after all.


Post a Comment for "Ajax Serialize; Cant 'read' Variables In PHP"