How to use jqXHR with Jquery

筅森魡賤 提交于 2019-12-11 15:02:20

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/22799398/how-to-use-jqxhr-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!