I am a complete beginner with JavaScript and jQuery.
When I query my API I will normally get JSON like this:
{
"soc": 9271,
"series": [
{
"year": 2013,
"estpay": 370
},
{
"year": 2012,
"estpay": 430
}
]
}
However if my query is invalid I will get JSON like this:
{
"error": "Some message here . . . .."
}
So my question is - what is the syntax to detect the error message and then set up an IF / ELSE type of response? i.e. If error message do this.. If no error message do something else.
You can try using an implemented JSON tool which has this methods built inside.
secondly you can try and use this:
if (response){
try{
a=JSON.parse(response);
}catch(e){
alert(e); //error in the above string(in this case,yes)!
}
}
Good luck!
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