Home >Web Front-end >JS Tutorial >JQuery.Ajax error debugging help information introduction_jquery

JQuery.Ajax error debugging help information introduction_jquery

WBOY
WBOYOriginal
2016-05-16 17:30:26977browse
下面是Jquery中AJAX参数详细列表:
timeout Number 设置请求超时时间(毫秒)。此设置将覆盖全局设置。
async Boolean (默认: true) 默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。
beforeSend Function 发送请求前可修改 XMLHttpRequest 对象的函数,如添加自定义 HTTP 头。XMLHttpRequest 对象是唯一的参数。
<span>function</span> (XMLHttpRequest) { <span>this</span>; <span>// the options for this ajax request</span> }
cache Boolean (默认: true) jQuery 1.2 新功能,设置为 false 将不会从浏览器缓存中加载请求信息。
complete Function 请求完成后回调函数 (请求成功或失败时均调用)。参数: XMLHttpRequest 对象,成功信息字符串。
<span>function</span> (XMLHttpRequest, textStatus) { <span>this</span>; <span>// the options for this ajax request</span> }
contentType String (默认: "application/x-www-form-urlencoded") 发送信息至服务器时内容编码类型。默认值适合大多数应用场合。
data Object, String 发 送到服务器的数据。将自动转换为请求字符串格式。GET 请求中将附加在 URL 后。查看 processData 选项说明以禁止此自动转换。必须为 Key/Value 格式。如果为数组,jQuery 将自动为不同值对应同一个名称。如 {foo:["bar1", "bar2"]} 转换为 '&foo=bar1&foo=bar2'。
dataType String

预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息返回 responseXML 或 responseText,并作为回调函数参数传递,可用值:

"xml": 返回 XML 文档,可用 jQuery 处理。

"html": 返回纯文本 HTML 信息;包含 script 元素。

"script": 返回纯文本 JavaScript 代码。不会自动缓存结果。

"json": 返回 JSON 数据 。

"jsonp": JSONP 格式。使用 JSONP 形式调用函数时,如 "myurl?callback=?" jQuery 将自动替换 ? 为正确的函数名,以执行回调函数。

error Function (默认: 自动判断 (xml 或 html)) 请求失败时将调用此方法。这个方法有三个参数:XMLHttpRequest 对象,错误信息,(可能)捕获的错误对象。
<span>function</span> (XMLHttpRequest, textStatus, errorThrown) { <span>// 通常情况下textStatus和errorThown只有其中一个有值 </span> <span>this</span>; <span>// the options for this ajax request</span> }
global Boolean (默认: true) 是否触发全局 AJAX 事件。设置为 false 将不会触发全局 AJAX 事件,如 ajaxStart 或 ajaxStop 。可用于控制不同的Ajax事件
ifModified Boolean (默认: false) 仅在服务器数据改变时获取新数据。使用 HTTP 包 Last-Modified 头信息判断。
processData Boolean (默认: true) 默认情况下,发送的数据将被转换为对象(技术上讲并非字符串) 以配合默认内容类型 "application/x-www-form-urlencoded"。如果要发送 DOM 树信息或其它不希望转换的信息,请设置为 false。
success Function 请求成功后回调函数。这个方法有两个参数:服务器返回数据,返回状态
<span>function</span> (data, textStatus) { <span>// data could be xmlDoc, jsonObj, html, text, etc...</span> <span>this</span>; <span>// the options for this ajax request</span> }

Copy code The code is as follows:

$(document).ready(function() {
            jQuery("#clearCac").click(function() {
                jQuery.ajax({
                    url: "/Handle/Do.aspx",
                    type: "post",
                    data: { id: '0' },
                    dataType: "json",
                    success: function(msg) {
                        alert(msg);
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        this; // 调用本次AJAX请求时传递的options参数
                    }
                });
            });
        });

 

一、error:function (XMLHttpRequest, textStatus, errorThrown)
{
}
(默 认: 自动判断 (xml 或 html)) 请求失败时调用时间。参数有以下三个:XMLHttpRequest 对象、错误信息、(可选)捕获的错误对象。如果发生了错误,错误信息(第二个参数)除了得到null之外,还可能是"timeout", "error", "notmodified" 和 "parsererror"。

textStatus:

 "timeout", "error", "notmodified" 和 "parsererror"。

二、error事件返回的第一个参数XMLHttpRequest有一些有用的信息:
 
XMLHttpRequest.readyState:

状态码
 - (未初始化)还没有调用send()方法
 - (载入)已调用send()方法,正在发送请求
 - (载入完成)send()方法执行完成,已经接收到全部响应内容
 - (交互)正在解析响应内容
 - (完成)响应内容解析完成,可以在客户端调用了

三、data:"{}", data为空也一定要传"{}";不然返回的是xml格式的。并提示parsererror.
 
四、parsererror的异常和Header 类型也有关系。及编码header('Content-type: text/html; charset=utf8');

5. XMLHttpRequest.status:
xx-Information prompt
These status codes indicate temporary responses. The client should be prepared to receive one or more 1xx responses before receiving a regular response.
-Continue.
-Switch protocol.

xx-Success
This type of status code indicates that the server successfully accepted the client request.
-OK. The client request was successful.
- Created.
-Accepted.
-Non-authoritative information.
-No content.
-Reset content.
-Part of the content.

xx-redirect
The client browser must take additional actions to fulfill the request. For example, the browser may have to request a different page on the server, or repeat the request through a proxy server.
-The object has been permanently moved, i.e. permanently redirected.
-The object has been temporarily moved.
-Unmodified.
-Temporary redirect.

xx-Client Error
An error occurred and there seems to be a problem with the client. For example, the client requests a page that does not exist, and the client does not provide valid authentication information. 400 - Bad request.
-Access Denied. IIS defines many different 401 errors, which indicate more specific error causes. These specific error codes show up in the browser but not in the IIS logs:
.1 - Login failed.
.2- Server configuration causes login failure.
.3-Not authorized due to ACL restrictions on resources.
.4-Filter authorization failed.
.5-ISAPI/CGI application authorization failed.
.7 – Access is denied by the URL authorization policy on the web server. This error code is specific to IIS6.0.
-Access Forbidden: IIS defines a number of different 403 errors, which indicate more specific error causes:
.1-Execution access is prohibited.
.2-Read access is prohibited.
.3-Write access is prohibited.
.4-Require SSL.
.5-Requires SSL128.
.6-IP address rejected.
.7-Require client certificate.
.8-Site access denied.
.9-Too many users.
.10-Invalid configuration.
.11-Password change.
.12-Access to the mapping table is denied.
.13-Client certificate revoked.
.14-Reject directory listing.
.15-Client access permission exceeded.
.16-The client certificate is not trusted or invalid.
.17-The client certificate has expired or is not yet valid.
.18 - The requested URL cannot be executed in the current application pool. This error code is specific to IIS6.0.
.19 - CGI cannot be executed for clients in this application pool. This error code is specific to IIS6.0.
.20-Passport login failed. This error code is specific to IIS6.0.
-Not found.
.0-(None) – No file or directory found.
.1-The web site cannot be accessed on the requested port.
.2-Web service extension locking policy blocks this request.
.3-MIME mapping policy blocks this request.
-The HTTP verb used to access this page is not allowed (method not allowed)
-The client browser does not accept the MIME type of the requested page.
- Proxy authentication required.
-Precondition failed.
–The request entity is too large.
-The request URI is too long.
–Unsupported media type.
–The requested range cannot be satisfied.
–Execution failed.
–Locked error.

xx-Server Error

The server was unable to complete the request because it encountered an error.
- Internal server error.
.12 - The application is busy restarting on the web server.
.13-The web server is too busy.
.15-Direct requests to Global.asa are not allowed.
.16–UNC authorization credentials are incorrect. This error code is specific to IIS6.0.
.18–URL authorization storage cannot be opened. This error code is specific to IIS6.0.
.100-Internal ASP error.
- Header value specifies unimplemented configuration.
- The web server received an invalid response when acting as a gateway or proxy server.
.1-CGI application timed out.
.2-CGI application error. application.
-The service is unavailable. This error code is specific to IIS6.0.
-Gateway timeout.
-HTTP version is not supported.
FTP

xx - Positive initial reply
These status codes indicate that an operation has started successfully, but the client would like another reply before proceeding with the new command .
Restart tag reply.
Service is ready and will start in nnn minutes.
Data connection is open and transfer is starting.
The file status is normal and the data connection is ready to be opened.

xx-positive completion reply
An operation has been completed successfully. Clients can execute new commands. 200 command OK.
The command was not executed, there are too many commands on the site.
System status, or system help reply.
Directory status.
File status.
Help message.
NAME system type, where NAME is the official system name listed in the AssignedNumbers document.
The service is ready to execute the new user's request.
The service closes the control connection. If appropriate, log out.
Data connection open, no transfer in progress.
Close data connection. The requested file operation was successful (for example, transferring the file or discarding the file).
Enter passive mode (h1, h2, h3, h4, p1, p2).
The user is logged in, continue.
The requested file operation is correct and completed.
PATHNAME created.

xx - Positive Intermediate Reply
The command was successful, but the server needs more information from the client to complete processing the request. 331 The username is correct and a password is required.
An account login is required.
The requested file operation is pending further information.

xx-Transient Negative Completion Reply
The command was unsuccessful, but the error is temporary. If the client retries the command, it may succeed. 421 Service Unavailable, closing the control connection. This response will be sent to any command if the service determines that it must shut down.
Unable to open data connection.
Connectionclosed;transferaborted.
The requested file operation was not performed. The file is unavailable (for example, the file is busy).
The requested operation terminated abnormally: A local error is being processed.
The requested operation was not performed. There is not enough system storage space.

xx - Permanent negative completion reply

The command was unsuccessful and the error is permanent. If the client retries the command, the same error will appear again. 500 Syntax error, command not recognized. This may include errors such as the command line being too long.
There is a syntax error in the parameter.
The command was not executed.
Wrong command sequence.
The command with this parameter was not executed.
Not logged in.
An account is required to store files.
The requested operation was not performed. The file is not available (e.g., file not found, no access rights).
The requested operation terminated abnormally: Unknown page type.
The requested file operation terminated abnormally: storage allocation exceeded (for the current directory or dataset).
The requested operation was not performed. Filename not allowed.
Common FTP status codes and their causes
-FTP uses two ports: 21 for sending commands and 20 for sending data. Status code 150 means that the server is preparing to open a new connection on port 20 to send some data.
- Command opens a data connection on port 20 to perform operations such as transferring files. The operation completed successfully and the data connection was closed.
-This status code is displayed after the client sends the correct password. It means the user has logged in successfully.
-This status code is displayed after the client sends the username. This status code will be displayed regardless of whether the username provided is a valid account on the system.
- The command opened a data connection to perform an operation, but the operation was canceled and the data connection was closed.
- This status code means that the user cannot log in because the username and password combination is invalid. If you are logging in with a user account, you may have typed the wrong username or password, or you may have selected to allow only anonymous access. If you log in using an anonymous account, IIS may be configured to deny anonymous access.
- The command was not executed because the specified file is not available. For example, the file you want to GET does not exist, or you are trying to PUT the file to a directory that you do not have write permissions for.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn