added ability to parse json when gettin json data

This commit is contained in:
coderaiser 2012-09-03 05:27:27 -04:00
parent 24557794a7
commit edfabb3b22

View file

@ -156,7 +156,26 @@ CloudClient.Utils = (function(){
if (lXMLHTTP.readyState === 4 /* Complete */ &&
lXMLHTTP.status === 200 /* OK */){
var lJqXHR = pEvent.target;
lSuccess_f(lJqXHR.response, lJqXHR.statusText, lJqXHR);
var lData = lJqXHR.response;
/* If it's json - parse it as json */
var lContentType = lXMLHTTP.getResponseHeader('content-type');
if(lContentType &&
lContentType.indexOf('application/json') === 0){
try{
lData = JSON.parse(lJqXHR.response);
}
catch(pError) {
/* if could not parse */
console.log('Error: could not parse' +
'json from server from url: ' +
pParams.url);
lData = lJqXHR.response;
}
}
lSuccess_f(lData, lJqXHR.statusText, lJqXHR);
}
};
}