How To Access Individual Values Of Form Data, Passed From An Html Page With Jquery.ajax(), Inside A Php Script?
I'm passing form data to a PHP script for processing via JS(jQuery.ajax()).  Problem is - I can't figure out a way to access individual form control values inside PHP( e.g. $_POST[
Solution 1:
You need to use serializeArray() on the form data instead of serialize. That will submit as an array.
data: $('#myform').serializeArray()
HTML
<inputtype="hidden" name="action" value="submit" />
PHP
if(isset($_POST["action"]))
{
    //code
}
Solution 2:
Add dataType: 'json' to your ajax handler and further modify your code like this:
$.ajax({
    type: 'POST',
    dataType: 'json', // changed to json
    url : 'PHPscript.php',
    data: {form : $('#myform').serialize()},
    success : function(data){ // added success handlervar myJSONresult = data;
     alert(myJSONresult.yourFieldName);
    }
});
Solution 3:
set traditional to true like
$.ajax({
traditional:true,
//your rest of the ajax code
});
on the php end you are getting the value fine the problem is at the form serialization end
Post a Comment for "How To Access Individual Values Of Form Data, Passed From An Html Page With Jquery.ajax(), Inside A Php Script?"