如何在JQuery中使用jqXHR [英] How to use jqXHR with Jquery

查看:159
本文介绍了如何在JQuery中使用jqXHR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个成功完成JQuery的GET请求。在成功参数中,我有一个带有三个参数的函数,就像它在JQuery示例中显示的那样。 textStatus是Success,jqXHR显示为[object Object],数据为空。这是我在开发者控制台中使用的调用:

  $。get(https://spreadsheets.google.com/feeds / data / key / sheetID / private / full?min-row = 1& min-col = 1& max-row = 1,
{},
function(data,textStatus,jqXHR)
{alert(data); alert(textStatus); alert(jqXHR);},xml);

我的问题是,成功函数的哪个参数包含XML?我一直没有找到任何从jqXHR获得xml的例子(我试过.responseXML和.xml)是jqXHR什么包含xml,我只是没有访问它的权利?我设置了电子表格,这样任何有链接的人都可以查看和编辑它,因此它不应该是授权问题。



这是我的开发者控制台输出。 / p>

解决方案

我发现它返回null,因为即使电子表格完全可见并发布到Web上,您仍然需要访问令牌来读取或提交数据,通过AJAX请求。

您可以通过在URL的末尾添加?alt = json-in-script作为JSON来访问它,并使用已发布的工作表进行阅读。请注意,您只能访问特定的行和列(它提供了整个工作表,并且不会将这些标题作为一行返回,它使用第一行作为命名方案),因此只能使用已发布的

数据应包含发回的XML,但为了接收它,您必须具有

  headers:{Authorization:Bearer+ yourAccessTokenVar},

或者我认为你可以使用?access_token = youraccesstokenhere作为URL参数。


I have a GET request successfully finishing with JQuery. In the success parameter, I have a function with the three parameters, like it shows on the JQuery examples. The textStatus is Success and the jqXHR shows as [object Object] and data is null. Here's my call I use in the developer console:

$.get("https://spreadsheets.google.com/feeds/cells/key/sheetID/private/full?                    min-row=1&min-col=1&max-row=1",
{},
function(data,textStatus,jqXHR)
{alert(data);alert(textStatus);alert(jqXHR);},"xml");

My question is, what parameter of the success function contains the XML? I haven't been able to find any examples that get xml from the jqXHR.(I've tried .responseXML and .xml) Is jqXHR what contains the xml and I'm just not accessing it right? I have the spreadsheet set so anyone with the link can view and edit it so it shouldn't be an authorization issue.

Here's my developer console output if that helps.

解决方案

I found out that it's returning null because even if the spreadsheet is completely visible and published to the web you still need an access token to read or submit data, via AJAX requests.

You can read using a published sheet by accessing it as JSON by appending "?alt=json-in-script" at the end of the URL. Note that you can't access specific rows and columns only (it gives the whole sheet and also doesn't return the headers as a row, it uses the first row for a naming scheme) doing this and it is read only using a published sheet.

data should contain the XML sent back but in order to recieve it you must have

headers: {Authorization: "Bearer " + yourAccessTokenVar},

in the headers or I think you can use "?access_token=youraccesstokenhere" as a URL parameter.

这篇关于如何在JQuery中使用jqXHR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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