How to use jqXHR with Jquery

2019-09-16 15:27发布

问题:

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.