开发者

Ajax request fails, only in Safari, only when XML is cached

开发者 https://www.devze.com 2023-02-25 05:19 出处:网络
I\'m trying to write a web app that looks like an iPad application, with offline usability.To do so, I instruct the browser to cache my files using a manifest, etc.When I try to ajax the xml, it works

I'm trying to write a web app that looks like an iPad application, with offline usability. To do so, I instruct the browser to cache my files using a manifest, etc. When I try to ajax the xml, it works the first time, but fails subsequent times. Funny thing is, it "fails", but xhr.responseXML is correct!

This is only an issue in Safari, whether on Windows or on the iPad. The issue only manifests on loads from cache, everything works fine the first time.

thrownError is "", xhr.status is 0, xhr.statusText is "error".

$.ajax({
    type: "GET",
    url: "data.xml",
    dataType: "xml",
    success: function(xml) {
        do_stuff(xml);
    },

    error: function (xhr, ajaxOptions, thrownError) {
        do_stuff(xhr.responseXML); // Why does this work?
    }
});

Any ideas? My best guess is that the xml is being loaded with the 开发者_运维技巧wrong MIME type?


When your page initially loads, the data.xml is not in the cache yet, so the ajax call goes directly to the server. Since you have have the url for the xhr request listed in the cache manifest, your browser will make a non-xhr request for it and store it in the cache. Subsequent loads of the page will load from the cache and return the non-xhr request.

Make sure that you can access the data.xml as a non-xhr request, and that it contains the data that you want displayed.

0

精彩评论

暂无评论...
验证码 换一张
取 消