I am trying to make an ajax call and return a response. The problem is I can't seem to figure out how to get at the response. Here is my javascript code:
$.ajax({
type: "POST",
url: "inc.test.php",
data: {list:postData},
dataType: "json",
success: function(response){
if(response.success == 1){
alert (response.testdata);
}},
error: function(jqXHR, textStatus, errorThrown){
console.log(errorThrown);
console.log(textStatus);
}
});
Here is my inc.test.php code sending the json data back:
if($result)
{
$arr=array(
"success" => 1,
"testdata" => 'Testing');
echo json_encode($arr);
}
In my Console/Response I see this:
{"success":1,"testdata":"Testing"}
I've read tons of articles and can't seem to figure out whats going on. Please help!