I am trying to send data from Jquery to PHP. This is what I have:
var jsonArray = JSON.stringify(dataArray);
$.ajax({
type: "POST",
url: "addcar_details.php",
data: {data : jsonArray},
dataType: "json",
success: function(data) {
console.log("sent");
}
});
I am trying to see what I have got in the "$_POST" from the "addcar_details.php" file. It is empty and I am not sure what I am missing for this to be working.
Thanks in advance :)
Try in this way
var jsonArray = {field1:'Field 1 Value',field2:'Field 2 Value'};
$.ajax({
method: "POST",
url: "addcar_details.php",
data: jsonArray,
success: function(data) {
console.log(data);
}
});
You should use method: 'POST'
$.ajax({
method: "POST",
url: "addcar_details.php",
data: {'data' : jsonArray},
dataType: "json",
success: function(data) {
console.log("sent");
console.log(data);
},
error: function() {
console.log("there was some error");
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.