相关疑难解决方法(0)

jQuery和AJAX响应头

所以我有这个jQuery AJAX调用,响应来自服务器的302重定向形式.我想采用这种重定向并将其加载到iframe中,但是当我尝试使用javascript警报查看标题信息时,即使firebug正确地看到它,它也会出现空值.

这是代码,如果它有帮助:

$j.ajax({
    type: 'POST',
    url:'url.do',
    data: formData,
    complete: function(resp){
        alert(resp.getAllResponseHeaders());
    }
});
Run Code Online (Sandbox Code Playgroud)

我真的无法访问服务器端的东西,以便将URL移动到响应主体,我知道这将是最简单的解决方案,因此任何有关解析标头的帮助都会非常棒.

ajax jquery redirect header http-status-code-302

153
推荐指数
7
解决办法
30万
查看次数

xmlHttp.getResponseHeader +不适用于CORS

我在.NET 4上有一个asp.NET WCF.该服务用于验证用户.我们正在提交用户名和密码,然后应返回包含身份验证cookie的HTTP标头.使用本地托管的测试页面,这是正常的.我现在正在访问头域信息跨域.我已将测试页安装在另一台计算机上,并配置为调用WCF.呼叫正常,呼叫中的"数据"回复正确.但是,我无法使用以下任一方法访问标头信息:

alert(xmlHttp.getAllResponseHeaders());
Run Code Online (Sandbox Code Playgroud)

要么

alert(xmlHttp.getResponseHeader("Set-Cookie"));
Run Code Online (Sandbox Code Playgroud)

使用IE中的调试器和Firefox的"Live HTTP Header"插件,我可以看到正在返回标头信息.

在我的全局ajax页面中,我设置了处理CORS的响应.

private void EnableCrossDomainAjaxCall()
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");


    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {

        HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");

        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我用来调用服务的AJAX:

$("#btnLogin").click(function(e) {
    var geturl;
    geturl = $.ajax({
        // type: "POST",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: 'http://10.0.4.66/AuthenticationService.svc/Login?Name=test&password=pwsd',
        // url: '../SecurityServer/AuthenticationService.svc/Login?Name=test&password=pwsd',
        dataType: "jsonp",
        error: function(request, status, error) {
            alert('Error Occured');
        },
        crossdomain: true,
        success: function(data, textStatus, xmlHttp) {
            // alert(xmlHttp.getResponseHeader("Content-Type"));
            document.write(xmlHttp.getResponseHeader("Content-Type") + "<br/>");
            alert(xmlHttp.getAllResponseHeaders()); …
Run Code Online (Sandbox Code Playgroud)

authentication wcf jquery wcf-security cors

22
推荐指数
2
解决办法
2万
查看次数

ajax响应:无法读取响应中的所有标头

我正在使用 ajax ( ) 发出发布请求CORS,并且正在设置标头 ( Content-Type:application/x-www-form-urlencoded) 并且我正在尝试读取响应的标头。这是我所做的:

function makePostRequest(url, data, headers, httpVerb, dataType, elementId) {
    $.ajax({
        url: url,
        type: httpVerb,
        data: data,
        headers: headers,
        dataType: dataType,
        success: function(data, textStatus, jqXHR) {
            $("#" + elementId).val(jqXHR.responseText);
            alert(JSON.stringify(jqXHR));
        },
        error: function(jqXHR, textStatus, errorThrown) {
            $("#" + elementId).val(jqXHR.responseText);
        }
    }).then(function(data, status, xhr) {
        console.log(xhr.getAllResponseHeaders());
    });
}
Run Code Online (Sandbox Code Playgroud)

但在控制台中仅打印

Content-Type: application/x-www-form-urlencoded; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

在 chrome 开发者工具中我看到: 在此输入图像描述

如何获取所有这些标头?

PS:我使用的是 Chrome,而不是 Firefox ()

我问如何获取所有标头,而不是为什么我只得到一个标头(如果不可能,我会接受这个答案)。

ajax response-headers

3
推荐指数
1
解决办法
1532
查看次数

无法获取jQuery AJAX响应头

这就是我正在尝试的:

$.ajax({
  type: 'GET',
  url: 'http://imgur.com/upload/',
  data: {
    url: 'http://upload.wikimedia.org/wikipedia/commons/3/3e/Phalaenopsis_JPEG.png'
  },
  complete: function(jqXHR, textStatus) {
    console.log(jqXHR.getAllResponseHeaders());
  }
});
Run Code Online (Sandbox Code Playgroud)

我只是得到一个空字符串.

任何帮助,将不胜感激.

编辑:

这些是我在Firebug中可以看到的响应头:

Server: nginx
Date: Sat, 02 Jul 2011 03:04:26 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: IMGURSESSION=asdfasdfasdfasdf; path=/; domain=.imgur.com
SERVERID=www4; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://imgur.com/ocuVX
Content-Encoding: gzip
Vary: Accept-Encoding

javascript ajax jquery http-headers response-headers

2
推荐指数
1
解决办法
8614
查看次数