I've got a page that will get a quick login check and access a web service for some JSON data. The data it's returning looks like this:
{ 'RESPONSE' : 'INVALID','CAMPAIGNID' : '0','MORELINK' : '' }
The code I'm using to get this data and attempt to pop a modal window based on the information is:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Login.asmx/Logon",
data: strData,
dataType: "json",
success: function (response) {
$('#divResp').html(response.d);
$(response.d).each(function(index,item){
alert(item.campaignid);
});
if (res.indexOf('invalid') >= 0){
//invalid account information UNP
foo = "You entered an invalid account number or password";
showDialog('screenActivate.asp',test_imgName);
}
if (res.indexOf('none') >=0) {
//do not deliver splash screen
foo = "No splash screen for YOU!";
}
if (res.indexOf('error') >=0) {
//general error
foo = "You entered an error";
}
if (res.indexOf('frozen') >=0) {
//member is locked out from numberous failed attempts
foo = "You have too many failed attempts. Your account has been locked";
}
if (res.indexOf('.png') >=0) {
imgName = (response.d);
showDialog('screenActivate.asp',test_imgName);
}
alert(foo);
$('#divResp').html(response.d);
}
});
$('#divQuery').ajaxError(function(evt, request, settings){
$('#divResp').html("Web services timeout. Please try again.");
});
}
The challenge is, either I get no information (Undefined) or as is with this current iteration, an error from Firebug that states uncaught exception: Syntax error, unrecognized expression: 'INVALID'
Am I not parsing the JSON response properly?
Relevant comment to answer
I pasted: "d":"{ 'RESPONSE' : 'INVALID','CAMPAIGNID' : '0','MORELINK' : '' } " into the jsonlint.com and that tool says the JSON is valid. When I attempt to loop through response.d with an each statement, it seems to go character by character.