The ParserError of error handling in Jquery Ajax

Source: Internet
Author: User

The ParserError of error handling in Jquery Ajax
01 $.ajax({
02         type: "POST",
03         contentType: "application/json",
04         url: myurl,
05         <font color="#ff0000">data</font>: {},
06         timeout: 30000, //超时时间:30秒
07          dataType: ‘json‘,
08         <font color="#ff0000">error</font>: function(XMLHttpRequest, textStatus, errorThrown){
09         },
10         success: function(result) {
11           // TODO: check result
12         }
13  });
error:function (XMLHttpRequest, textStatus, errorThrown)
{
}
(默认: 自己主动推断 (xml 或 html)) 请求失败时调用时间。參数有下面三个:XMLHttpRequest 对象、错误信息、(可选)捕获的错误对象。假设发生了错误,错误信息(第二个參数)除了得到null之外,还可能是"timeout", "error", "notmodified""parsererror"
The first parameter returned by the error event XMLHttpRequest has some useful information: xmlhttprequest.readystate: Status Code  0-(uninitialized) has not yet called the Send () method  1- (load) called the Send () method, which is sending  a request 2-(loaded) the Send () method has finished running, has received all response content  3-(interaction) is parsing  the response Content 4-(completed) The response content resolved, can be called in the client
Xmlhttprequest.status Properties: Some error codes:
(see below)
Data: "{}", the data is empty also must pass "{}"; otherwise the return is in XML format. and prompt ParserError.
See Juqery Source code:
01 httpData: function( xhr, type, s ) {
02         var ct = xhr.getResponseHeader("content-type") || "",
03             xml = type === "xml"|| !type && ct.indexOf("xml") >= 0,
04             data = xml ? xhr.responseXML : xhr.responseText;
05
06         if( xml && data.documentElement.nodeName === "parsererror") {
07             jQuery.error( "parsererror");
08         }
09
10         // Allow a pre-filtering function to sanitize the response
11         // s is checked to keep backwards compatibility
12         if( s && s.dataFilter ) {
13             data = s.dataFilter( data, type );
14         }
15
16         // The filter can actually parse the response
17         if( typeof data === "string") {
18             // Get the JavaScript object, if JSON is used.
19             if( type === "json"|| !type && ct.indexOf("json") >= 0 ) {
20                 data = jQuery.parseJSON( data );
21
22             // If the type is "script", eval it in global context
23             } elseif ( type === "script"|| !type && ct.indexOf("javascript") >= 0 ) {
24                 jQuery.globalEval( data );
25             }
26         }
27
28         returndata;
29     },
会发现 parsererror的异常和 Header 类型也有关系。及编码
1 header(‘Content-type: text/html; charset=utf8‘);
Technorati Tags: xmlhttprequest.status
 The 1xx-information indicates that these status codes represent a transient response.  The client should be prepared to receive one or more 1xx responses before receiving a regular response.  100-Continue.  101-Switch protocol.  2xx-success Such status codes indicate that the server successfully accepted the client request. 200-OK.  The client request was successful.  201-created.  202-accepted.  203-Non-authoritative information.  204-no content.  205-Reset the content.  206-Partial content. The 3xx-redirect client browser must take many other actions to implement the request.  For example, the browser might have to request a different page on the server, or repeat the request through Proxy server.  301-The object has been permanently moved, that is, permanent redirection.  302-The object has been temporarily moved.  304-not changed.  307-Temporary redirection. 4xx-client error occurred, client seems to have a problem. For example, the client requests a page that does not exist, and the client does not provide valid authentication information.  400-Bad request. 401-an interview was denied. IIS defines a number of different 401 errors, which indicate a more detailed cause of the error.  These detailed error codes are displayed in the browser, but are not displayed in the IIS log: 401.1-Logon failed.  Login failed due to 401.2-server configuration.  401.3-the ACL is not authorized because of a resource limitation.  401.4-Filter Authorization failed.  401.5-ISAPI/CGI application authorization failed. 401.7– access is denied by the URL authorization policy on the webserver.  This error code is dedicated to IIS6.0.  403-No Access: IIS defines a number of different 403 errors that indicate a more detailed cause of the error: 403.1-running access is forbidden.  403.2-Read access is forbidden.  403.3-is forbidden to write an interview.  403.4-Requires SSL.  403.5-Requires SSL128.  The 403.6-IP address is rejected.  403.7-Requires client certificate.  403.8-website access is denied.  403.9-Excessive number of users.  403.10-Invalid configuration.  403.11-password changes.  403.12-Deny access to the mapping table.  The 403.13-client certificate was revoked.  403.14-Reject Folder list.  403.15-Client access permission exceeded.  403.16-client certificate is not trusted or invalid.  The 403.17-client certificate has expired or is not yet valid. 403.18-InThe requested URL cannot be run in the current application pool.  This error code is dedicated to IIS6.0. 403.19-CGI cannot be run for the client in this application pool.  This error code is dedicated to IIS6.0. 403.20-passport Login failed.  This error code is dedicated to IIS6.0.  404-not found.  404.0-(None) – No files or folders found.  404.1-Unable to access the Web site on the requested port.  The 404.2-web service extension lockout policy blocks this request.  The 404.3-mime mapping policy blocks this request.  405-The HTTP verb used to access this page is not agreed (the method is not agreed) 406-client the browser does not accept the MIME type of the requested page.  407-proxy authentication is required.  412-Precondition failed.  413– request entity is too large.  414-The request URI is too long.  415– media types not supported.  The range requested by 416– is not sufficient.  417– failed to run.  423– a locked error.  5xx-server error Server could not complete the request because it encountered an error.  500-Internal server error.  The 500.12-application is busy starting up again on webserver.  500.13-webserver is too busy.  500.15-Do not agree to request Global.asa directly. 500.16–unc authorization credentials are not correct.  This error code is dedicated to IIS6.0. The 500.18–url authorization store cannot be opened.  This error code is dedicated to IIS6.0.  500.100-Internal ASP error.  501-The header value specifies the configuration that is not implemented.  An invalid response was received when 502-webserver was used as a gateway or proxy server.  The 502.1-cgi application timed out. 502.2-CGI Application error.  Application. 503-The service is not available.  This error code is dedicated to IIS6.0.  The 504-gateway timed out.  The 505-http version number is not supported.  FTP 1xx-Affirmative Initial reply These status codes indicate that an operation has started successfully, but the client wants to have a reply before continuing with the new command.  110 start tag reply again.  120 service is ready and starts in nnn minutes.  125 The data connection is turned on and the transmission is beginning.  150 file status OK, ready to open data connection. 2xx-definitely finished. An operation has been successfully completed. The client is able to run the new command.  200 command OK. 202 Command not running, there are too many commands on the site.  211 System Status, or system help reply.  212 folder status.  213 file status.  214 Help message.  215NAME system type, in which name is the official system name listed in the Assignednumbers document.  220 service ready to run the new user's request. 221 Service closes the control connection.  If appropriate, please log out.  225 Data connection Open, no in-progress transfer. 226 Close the data connection.  The requested file operation was successful (for example, transferring a file or discarding a file).  227 Enter passive mode (H1,H2,H3,H4,P1,P2).  230 The user is logged in and continues.  250 The requested file operation is correct and complete.  257 "PATHNAME" has been created. 3xx-Affirmative Intermediate reply The command was successful, but the server needed a lot of other information from the client to complete the processing of the request.  331username correct, need password.  332 login account required.  350 The requested file operation is waiting for further information. 4xx-transient negation complete reply The command was unsuccessful, but the error was temporary. Assuming that the client retries the command, it may run successfully. 421 service is not available and the control connection is shutting down.  Assuming the service determines that it must be closed, this response will be sent to whatever command.  425 The data connection cannot be opened.  426connectionclosed;transferaborted. 450 The requested file operation was not run.  The file is not available (for example, the file is busy).  451 requested operation aborted: Local error is being processed. 452 the requested operation was not run.  The system does not have enough storage space. 5xx-permanent Negation The command is unsuccessful and the error is permanent. Assuming the client retries the command, the same error will occur again. 500 syntax error, command not recognized.  This may contain errors such as the command line being too long.  501 There are syntax errors in the number of parameters.  502 The command is not running.  503 wrong sequence of commands.  504 The command that did not run the parameter.  530 not logged in.  532 account required to store files. 550 the requested operation was not run.  The file is not available (for example, no files found, no access rights).  551 requested operation aborted: unknown page type.  552 The requested file operation terminated abnormally: storage allocation exceeded (for the current folder or dataset). 553 The requested operation was not run.  The name of the file that does not agree. Common FTP status codes and their causes 150-ftp uses two port:21 for sending commands and 20 for sending data. The status code 150 indicates that the server is ready for the PorOpen a new connection on the T20 and send some data. 226-The command opens a data connection on port20 to run operations, such as transferring files.  The operation completes successfully and the data connection is closed. After 230-client sends the correct password, the status code is displayed.  It indicates that the user has successfully logged on. 331-client The status code is displayed after the username is sent.  This status code is displayed regardless of whether the provided username is a valid account in the system.  426-The command opens the data connection to run the operation, but the operation has been canceled and the data connection is closed. 530-The status code indicates that the user cannot log on because the username and password combinations are not valid. Assuming you are logged on with a user account, you may be typing the wrong username or password, or you may choose to simply consent to anonymous access.  Assuming you are logged on with an anonymous account, the configuration of IIS may deny anonymous access. 550-The command was not run because the specified file is not available. For example, the file you want to get does not exist, or you try to put the file in a folder where you do not have write permission.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.