jomin_george94 jomin_george94 - 1 month ago 7
Ajax Question

Issue with sending data to PHP from JQuery

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 :)

Answer

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");
    }
});

Read more here.

Comments