When debugging an Ajax yesterday, it was found that even if the status was 201, jquery's Error event would still be triggered. StatusText is "ParseError".
By querying on the StackOverflow, poke here.
Plus parameters
DataType: "Text"
can be solved.
The reason for the problem is also very detailed in the comments. But not right, he made a mistake about the position of convert, and before jquery judged the status code, it had been ajaxconvert.
Determine if successful, determine the size of status Issuccess = status >= && status < 300 | | Status = = 304; Get Response Data if (responses) {response = Ajaxhandleresponses (s, jqxhr, responses); }//Convert no matter what (that's responsexxx fields is always set), where the response data is converted. Below is attached Ajaxconvert source code. Response = Ajaxconvert (s, Response, JQXHR, issuccess); If successful, handle type chaining if (issuccess) {//Set the If-modified-since and/or IF-NONE-MATC h header, if in ifmodified mode. if (s.ifmodified) {modified = Jqxhr.getresponseheader ("last-modified"); if (modified) {Jquery.lastmodified[cacheurl] = modified; } modified = Jqxhr.getresponseheader ("ETag"); if (modified) {Jquery.etag[cacheurl] = modified; }}//If no content if (status = = = 204 | | s.type = = = "HEAD") {statustext = "nocontent"; If not modified, determines whether the state is 304
} else if (status = = = 304) { statustext = "notmodified"; If we have the data, let ' s convert it. } else { statustext = response.state; Success = Response.data; Error = Response.error; issuccess =!error; } } else { //Extract error from StatusText and normalize for non-aborts error = statustext; if (status | |!statustext) { statustext = "error"; if (Status < 0) { status = 0; } } }
function Ajaxconvert (s, Response, JQXHR, issuccess) {var conv2, current, conv, tmp, prev,converters = {},//work with a Copy of datatypes in case we need to modify it for conversiondatatypes = S.datatypes.slice ();//Create converters map with Lowercased Keysif (datatypes[1]) {for (conv in s.converters) {converters[conv.tolowercase ()] = s.converters[Conv ];}} Current = Datatypes.shift ()//Convert to each sequential Datatypewhile (current) {if (s.responsefields[current]) {J qxhr[s.responsefields[Current]] = response;} Apply the Datafilter if Providedif (!prev && issuccess && s.datafilter) {response = S.datafilter (res Ponse, S.datatype);} Prev = Current;current = Datatypes.shift (), if (current) {//There ' s only work to do if current DataType is non-autoif ( Current = = = "*") {current = prev;//Convert response if Prev DataType are Non-auto and differs from current} else if (pre V!== "*" && prev!== current) {//Seek a direct Converterconv= converters[prev + "" + Current] | | converters["*" + current];//If none found, seek a Pairif (!conv) {for (conv2 in converters) {//If conv2 outputs C Urrenttmp = Conv2.split (""); if (tmp[1] = = = current) {//If Prev can is converted to accepted Inputconv = Converters [prev + "+ tmp[0]] | | converters["*" + tmp[0]];if (CONV) {//Condense equivalence convertersif (CONV = = True) {conv = converters[conv 2];//Otherwise, insert the intermediate DataType} else if (converters[Conv2]!== true) {current = tmp[0];d atatypes . Unshift (tmp[1]);} Break;}}}} Apply Converter (if not equivalence) if (conv!== true) {//Unless errors is allowed to bubble, catch and return T HEMIF (CONV && s.throws) {response = conv (response);} else {try {response = conv (response);} catch (e) {RE Turn {state: ' ParserError ', Error:conv? e: ' No conversion from ' + prev + ' to ' + Current}}}}} return {state: "Success", Data:response};}
P.S. In the case of Ajax synchronization requests, the Onreadystatechang event is not triggered.
P.s.jquery determines the status 204 (return null), or 304 (the user uses the cached document).
Comments:
· 204-no Content does not have a new document, the browser should continue to display the original document. This status code is useful if the user refreshes the page on a regular basis and the servlet can determine that the user's document is new enough.
· The 304-not Modified client has a buffered document and issues a conditional request (typically providing a if-modified-since header indicating that the customer only wants to update the document than the specified date). The server tells the customer that the original buffered document can continue to be used.
Ajax status of 201 still triggers jquery Error event issue