hello I would like to post multiple data to a php file with jQuery ajax but when I execute the function it’s retuning nothing and the php also doesn’t get the data
my function looks like this:
function sendForm(){
jQuery.ajax({
url: <?php echo $path; //this the url where the php file is ?>,
type: 'POST',
data: {
addressOne: jQuery('#Form #table .key :input').serialize(),
addressTwo: jQuery('#Form #table_2 .key :input').serialize(),
additionalData: jQuery('#Form #More :input').serialize(),
preloaded: <?php echo serialize($array); ?>,
action: 'sendIt'
},
async: false,
cache: false,
success: function(data){
alert(data); //or console.log(data);
}
});
}
and in the php I do something like this:
<?php
function handleData() {
parse_str($_POST['addressOne'], $arrayOne);
parse_str($_POST['addressTwo'], $arrayTwo);
parse_str($_POST['additionalData'], $arrayThree);
$preloaded = unserialise($_POST['preloaded']);
//than do some stuf here for example print_r all...
}
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
switch($action) {
case 'sendIt' : handleData();
break;
//etc...
}
}
?>
I don’t know what I’m doing wrong? Is there a better way to post multiple data?
If I use only one data like I’m serialising the whole form and do not post the serialized php array than it works fine, but I would like to use this four separate data.
You mistyped your ajax query
urlwithulrConsider using a plugin for your browser like Web Developer, I’m pretty sure it would have picked up the error and you wouldn’t have needed to ask here.
Edit: if you are still having troubles, validate the data you are going to send with some
alert, validate that yourphpscript does what you want it to do by navigating to it manually from the browser, since you provide asuccesscallback, any reason you’re notasync, etc… validate everything