I'm just getting started on this web project. Typescript is being used. I'm looking at this:
$.ajax({
type: method,
url: url,
xhrFields: {
withCredentials: $.support.cors
},
crossDomain: $.support.cors,
data: data,
dataType: (this.options.fallbackMethod ? this.options.fallbackMethod : "json")
}).then(
(data, textStatus, jqXHR) => { if (typeof (successCallback) === "function") successCallback(data, textStatus, jqXHR); },
(jqXHR, textStatus, errorThrown) => {
console.log("ajax failed: ");
console.log(errorThrown);
console.log(jqXHR);
console.log(textStatus);
if (typeof (failCallback) === "function") failCallback(jqXHR, textStatus, errorThrown);
}
);
This gets called when we make a request to the server. When I get a bad request from the server, I see in Firebug and Fiddler, that the server is sending back a JSON object with the error code (e.g. 400), and the error message ("couldn't find that resource.").
What I don't understand though, is how to get that JSON object back so I can parse it. When I log all the parameters (errorThrown, jqXHR, textStatus), there doesn't seem to be a way to get the JSON back. I just see the responseText property that has the message and error code bundled up in a string, but not the JSON object. I did do a check to make sure that the dataType
was in fact json before this method was called. Any thoughts? Thanks in advance.