I'm trying to setup a simple AJAX call that sends it's data via JSON to my PHP script, which then returns the data.
But I am having no luck.
Here is my code for sending:
$.ajax({
url: ROOT+'Address/fetchAddress',
type: 'POST',
async: false,
dataType: 'json',
data: {
json: {
"Id":"0",
"Name":"Jim"
}
},
error: function(a, b)
{
alert(b)
},
success: function(data)
{
data = $.parseJSON(data);
alert(data)
}
})
Serverside:
public function fetchAddress()
{
$JSON = $_POST['json'];
echo json_decode($JSON);
}
But I am getting "parseerror" in alert box and if I inspect the response I get:
Warning: json_decode() expects parameter 1 to be string, array given in ...public_html\controllers\Address.php on line 20