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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:32:07  来源:igfitidea点击:

getResponseHeader is not a function

jquery

提问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 successfunction is not terminated.

首先,您的设置对象格式不正确,该success功能没有终止。

Edit:Seems that you are using jQuery 1.3.x, if so, the $.ajaxfunction 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 successcallback its executed three arguments are passed (success(data, textStatus, XMLHttpRequest)), you need to call the getResponseHeaderon 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)当你这样做时。