相关疑难解决方法(0)

使用jQuery.ajax和JSONP设置标头?

我试图用jQuery访问谷歌文档.这是我到目前为止所拥有的:

var token = "my-auth-token";
$.ajax({
  url: "http://docs.google.com/feeds/documents/private/full?max-results=1&alt=json",
  dataType: 'jsonp',
  beforeSend: function(xhr) {
    xhr.setRequestHeader("Authorization", "GoogleLogin auth=" + token);
  },
  success: function(data, textStatus, XMLHttpRequest) {
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
  }
});
Run Code Online (Sandbox Code Playgroud)

如果我设置dataTypejsonp(来自使用jQuery创建跨域Ajax请求),它不允许我设置标头.如果我遗漏jsonp,我无法提出跨域请求.如果我使用jQuery.getJSON,我不能传入任何标题...

在制作跨域ajax请求时(在jQuery中)有没有办法定义自定义标头?

ajax jquery header cross-domain

46
推荐指数
1
解决办法
4万
查看次数

标签 统计

ajax ×1

cross-domain ×1

header ×1

jquery ×1