打印服务器响应
Print Server Response
我正在使用一个在 Perl 中验证的表单。我能够在网络 XHR 下的 chrome 开发工具中看到响应。我想打印 'response' 错误。
看起来像这样:
{type: "error", message: "Unable to located your account by this email address: tim@example.com"}
message:"Unable to located your account by this email address: tim@example.com"
type: "error"
并且 header 请求如下所示:
/vsap/mail_id.html?email=tim%40example.com
我是否可以通过 jQuery 访问错误消息?
我建议您阅读 documentation. I assume that's how you do the request to the server. You can provide a fail()
callback that is documented here。因此,您应该在 .fail(function(jqXHR, status, error){})
调用之后添加另一个调用,并在该函数内部执行您需要的错误。此外,您可以使用状态以不同的方式处理不同的错误类型。失败的文档是:
A function to be called if the request fails. The function receives
three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a
string describing the type of error that occurred and an optional
exception object, if one occurred. Possible values for the second
argument (besides null) are "timeout", "error", "abort", and
"parsererror". When an HTTP error occurs, errorThrown receives the
textual portion of the HTTP status, such as "Not Found" or "Internal
Server Error." As of jQuery 1.5, the error setting can accept an array
of functions. Each function will be called in turn. Note: This handler
is not called for cross-domain script and JSONP requests. This is an
Ajax Event.
我正在使用一个在 Perl 中验证的表单。我能够在网络 XHR 下的 chrome 开发工具中看到响应。我想打印 'response' 错误。
看起来像这样:
{type: "error", message: "Unable to located your account by this email address: tim@example.com"}
message:"Unable to located your account by this email address: tim@example.com"
type: "error"
并且 header 请求如下所示:
/vsap/mail_id.html?email=tim%40example.com
我是否可以通过 jQuery 访问错误消息?
我建议您阅读 documentation. I assume that's how you do the request to the server. You can provide a fail()
callback that is documented here。因此,您应该在 .fail(function(jqXHR, status, error){})
调用之后添加另一个调用,并在该函数内部执行您需要的错误。此外,您可以使用状态以不同的方式处理不同的错误类型。失败的文档是:
A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event.