2

I have an application that uses a .appcache manifest. Everything works as expected, resources get cached:

CACHE MANIFEST

CACHE:
css/images/ajax-loader.gif
[...]

NETWORK:
http://docs.google.com/*

SETTINGS:
prefer-online

Now, when I request a CSV resource from http://docs.google.com like so:

$.get(url, function (data) {
  // do something with the data
}).fail(function () {
  alert("There was an error in loading current data from the server.");
});

the request fails even if I'm acutally online (on both Chrome and FF). Everything worked fine before I used the Appcache.

What is the correct way of requesting external resources while having an Appcache manifest?

3
  • I've come to the conclusion that it might in fact have to do with Cross-Origin Resource Sharing as I don't control google docs (It might have worked before because the relevant file was still in my Browser cache). Chrome shows a status code "cancelled", however, in FF my approach works beautifully. Why is that? Commented Aug 11, 2013 at 14:36
  • Look at the 'cache' section in this JQuery.ajax() documentation: api.jquery.com/jQuery.ajax. What happens if you use this instead of 'get()', with 'cache: false'? Commented Aug 11, 2013 at 15:48
  • @Holf Thanks for the suggestion, apparently the real problem was somewhere else, see my answer below (Cost me some hours). Thanks anyway! Commented Aug 11, 2013 at 16:20

2 Answers 2

1

As I mentioned in my comment, the problem was not (only) jQuery, but also CORS resp. Google Docs' lack of support of it ("Publish to web" means for download, not for requesting the resource from a different URL, i.e. origin. Apparently Google does not want to add a Header set Access-Control-Allow-Origin "*".

So what I did instead was follow this helpful guide: https://webapps.stackexchange.com/questions/11864/how-can-i-retrieve-records-from-a-google-spreadsheet-in-json-format and https://developers.google.com/gdata/samples/spreadsheet_sample (The URL is now not CSV but JSONP, it also changed to //spreadsheets.google.com/feeds/list/[...]/[...]/public/values?alt=json-in-script and jQuery automatically adds the callback=xxx when called with:

$.ajax({
  url : url,
  type : 'GET',
  dataType : 'jsonp',
  success : function (data) {
    for(var i in data.feed.entry) {
      console.log(entry['gsx$' + 'actualColumnHeader'].$t);
    }
  },
  error : function () {
    alert('Failed');
  }
});

This is not nice or clean by any means (Atom Feed instead of CSV or JSON just to parse it back? Seriously?), but it works for me.

Sign up to request clarification or add additional context in comments.

Comments

1

I've just get it working with tabletop. No more CORS issue.. for now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.