I've never worked with JSON before and it's not going well...
I have a PHP script that returns a JSON array(is that the correct term?)
The script returns:
{"items":1000,"mitems":0,"donations":0,"total":1000}
NOTE: The script also sets the Content-Type to application/json
Here is my front-end javascript to handle that response:
function ajax(){
$.ajax({
url: '../ajax/goal_ajax.php',
dataType: 'json',
success: function( data ){
// success! :D
alert('success');
}, error: function( data ){
// data.responseText is what you want to display, that's your error.
alert(data.responseText);
}
})
//progressBar.set('value',data.total);
//document.getElementById('txtCDInfo').innerHTML=txt;
}
When that function is called I get an alert with the following message:
{"items":1000,"mitems":0,"donations":0,"total":1000}
If everything was successful, I should get an alert that says success
, right?
Can someone please tell me what is going on here?
Thank you!
header('Content-Type: text/json')
– Shad Feb 1 at 0:27json
since he's specifyingjson
indataType
. Changeerror: function( data )
toerror: function(data, textStatus, errorThrown)
and doalert(textStatus)
to see the cause of the error. – webbiedave Feb 1 at 0:32