I want to use the jQuery $.ajax
to make a POST call sending some information (via POST like: page.aspx?var1=value
....).
But I also want jQuery to handle that the service is returning JSON so that I get back a JSON object.
var data = {name: _name, ...};
var request = $.ajax({
url: url,
type: "post",
data: data,
//dataType: "json"
});
As soon as I use dataType: "json"
, which allows me to receive the JSON object I get an parseerror on the request!
Hope you can help me out with that!
THANKS IN ADVACE!
From the requested url you have to make data in JSON format like
echo json_encode($response);
and then you will get that response JSON in success function like this:
$.ajax({
type:"POST",
url: "your_url",
data:data,
success: function (response){
var arr = $.parseJSON(response);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With