我正在尝试使用 jQuery 访问谷歌文档.到目前为止,这是我所拥有的:
I am trying to access google docs with jQuery. Here's what I have so far:
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) {
}
});
如果我将 dataType 设置为 jsonp(来自 使用 jQuery 进行跨域 Ajax 请求).如果我遗漏了 jsonp,我将无法发出跨域请求.如果我使用 jQuery.getJSON,我不能传入任何标题...
It doesn't allow me to set headers if I set the dataType to jsonp (from Make Cross Domain Ajax Requests with jQuery). If I leave out jsonp, I can't make the cross-domain request. If I use jQuery.getJSON, I can't pass in any headers...
在发出跨域 ajax 请求(在 jQuery 中)时,有什么方法可以定义自定义标头?
Is there any way to define custom headers when making a cross-domain ajax request (in jQuery)?
这是不可能的.
JSONP 请求通过创建 <script> 元素并将其 src 属性设置为请求 URL 来工作.
您不能向 <script> 元素发送的 HTTP 请求添加自定义标头.
A JSONP request works by creating a <script> element with its src attribute set to the request URL.
You cannot add custom headers to the HTTP request sent by a <script> element.
这篇关于使用 jQuery.ajax 和 JSONP 设置标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
用于创建头像的 jQuery/JavaScript 库?jQuery/JavaScript Library for avatar creation?(用于创建头像的 jQuery/JavaScript 库?)
如何做以下掩码输入问题?How to do following mask input problem?(如何做以下掩码输入问题?)
使用 DropKick Javascript 设置值/标签的问题Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 设置值/标签的问题)
如何对 jquery 插件中的私有方法进行单元测试?how to unit-test private methods in jquery plugins?(如何对 jquery 插件中的私有方法进行单元测试?)
stellar.js - 为垂直滚动网站配置偏移量/对齐元素stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 为垂直滚动网站配置偏移量/对齐元素?)
jQuery 屏蔽输入插件.当文本框获得焦点时选择所有jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽输入插件.当文本框获得焦点时选择所有内容)