getResponseHeader不是函数 [英] getResponseHeader is not a function
问题描述
我需要从另一个页面获取值.但是我收到以下代码此错误.我该如何解决?
I need to get a value from another page. But I get this error with the following code. How can I fix it?
$(document).ready(function() {
$("[name='submit']").click(function() {
$.ajax({
type: "POST",
data: $(".form-signup").serialize(),
url: "external.asp",
success: function(output) {
alert(output.getResponseHeader("Content-Length"));
},
error: function(output) {
$('.sysMsg').html(output);
}
});
});
});
推荐答案
首先,您的设置对象格式不正确,success
函数未终止.
First, your settings object is not well formed, the success
function is not terminated.
似乎您正在使用jQuery 1.3.x,如果使用的话,$.ajax
函数本身将返回XHR对象:
Seems that you are using jQuery 1.3.x, if so, the $.ajax
function itself returns the XHR object:
$(document).ready(function() {
$("[name='submit']").click(function() {
var xhr = $.ajax({
type: "POST",
data: $(".form-signup").serialize(),
url: "external.asp",
success: function(output, status) {
alert(xhr.getResponseHeader("Content-Length"));
},
error: function(output) {
$('.sysMsg').html(output);
}
});
});
});
对于jQuery 1.4+版本:
For jQuery 1.4+ versions:
然后,当传递success
回调函数执行的三个参数(success(data, textStatus, XMLHttpRequest)
)时,您需要在 XmlHttpRequest 对象上调用getResponseHeader
,第三个参数:
Then, when the success
callback its executed three arguments are passed (success(data, textStatus, XMLHttpRequest)
), you need to call the getResponseHeader
on the XmlHttpRequest object, the third argument:
$(document).ready(function() {
$("[name='submit']").click(function() {
$.ajax({
type: "POST",
data: $(".form-signup").serialize(),
url: "external.asp",
success: function(output, status, xhr) {
alert(xhr.getResponseHeader("Content-Length"));
},
error: function(output) {
$('.sysMsg').html(output);
}
});
});
});
这篇关于getResponseHeader不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!