jQuery JSONP ajax,未设置身份验证标头 [英] jQuery JSONP ajax, authentication header not being set

查看:116
本文介绍了jQuery JSONP ajax,未设置身份验证标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下设置向Google通讯录API发出ajax请求:

I'm trying to make an ajax request to the google contacts API with the following setup:

$.ajax({
  url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all",
  dataType: 'jsonp',
  data: {
    alt: 'json-in-script'
  },
  headers: {
    'Authorization': 'Bearer ' + token
  },
  success: function(data, status) {
    return console.log("The returned data", data);
  }
});

但是认证标头似乎没有设置。有什么想法?

But the Authentication header doesn't seem to get set. Any ideas?

推荐答案

我最近遇到了同样的问题。试试这个:

I had the same problem recently. Try this:

$.ajax({
  url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all",
  dataType: 'jsonp',
  data: {
    alt: 'json-in-script'
  },
  success: function(data, status) {
    return console.log("The returned data", data);
  },
  beforeSend: function(xhr, settings) { xhr.setRequestHeader('Authorization','Bearer ' + token); } 
});

编辑:看起来无法用JSONP完成。 修改JSONP请求的HTTP标头

Looks like it can't be done with JSONP. Modify HTTP Headers for a JSONP request

这篇关于jQuery JSONP ajax,未设置身份验证标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆