jQuery getResponseHeader 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2444489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getResponseHeader is not a function
提问by zurna
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);
}
});
});
});
回答by CMS
First, your settings object is not well formed, the success
function is not terminated.
首先,您的设置对象格式不正确,该success
功能没有终止。
Edit:Seems that you are using jQuery 1.3.x, if so, the $.ajax
function itself returns the XHR object:
编辑:似乎您使用的是 jQuery 1.3.x,如果是这样,$.ajax
函数本身将返回 XHR 对象:
$(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);
}
});
});
});
For jQuery 1.4+ versions:
对于 jQuery 1.4+ 版本:
Then, when the success
callback its executed three arguments are passed (success(data, textStatus, XMLHttpRequest)
), you need to call the getResponseHeader
on the XmlHttpRequestobject, the third argument:
然后,当success
回调的执行三个参数传递(success(data, textStatus, XMLHttpRequest)
),您需要调用getResponseHeader
上的XmlHttpRequest对象,第三个参数:
$(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);
}
});
});
});
回答by Andrew Potts
Is it a cross-domain call? You may be entering a whole new world of pain? (Cross Domain Resource Sharing GET: 'refused to get unsafe header "etag"' from Response) when you do that.
是跨域调用吗?您可能正在进入一个全新的痛苦世界?(跨域资源共享 GET: 'refused to get unsafe header "etag"' from Response)当你这样做时。