jQuery AJAX request failing in IE

前端 未结 8 1197
[愿得一人]
[愿得一人] 2020-11-30 03:42

The following AJAX call is failing in IE.

$.ajax({
    url:\"{{SITE_URL}}/content/twitter.json\",
    dataType:\"json\",
    error:function(xhr, status, erro         


        
相关标签:
8条回答
  • 2020-11-30 04:16

    What is the {{SITE_URL}} chunk giving is about. Try looking at the code in view source code of the browser. If the {{SITE _URL}} chunk has a trailing slash and that would make the request url:

    http://modomain.com//content/twitter.json
    

    Which could creep IE out?

    0 讨论(0)
  • 2020-11-30 04:25

    For the caching problem why don't you simple use the cache: false parameter?

    $.ajax({ 
        url: "yoururl",
        cache: false,
        ....
    
    0 讨论(0)
  • 2020-11-30 04:26

    is this a copy/paste? the one thing that gets me all the time is leaving the last ',' in an object constructor. that is, most browsers JS accept:

    o = { a:1, b:2, c:3, };
    

    but IE chokes on this because the comma after the last item. change it to:

    o = { a:1, b:2, c:3 };
    

    and it works.

    0 讨论(0)
  • 2020-11-30 04:27

    IE caches AJAX requests really aggressively (more so than Firefox, anyway). You need to set the Cache-Control headers in the response appropriately if this is not right for your site.

    0 讨论(0)
  • 2020-11-30 04:30

    Fixed, I changed the content-type from application/json; charset=utf8 to just plain application/json.
    I hate IE :)

    Also to avoid IE super-caching try this:

    var d = new Date();
    $.ajax({
            url:"{{SITE_URL}}/content/twitter.json?_="+d.getTime(), 
    ...Snip...
    

    That way each request is a new url for IE to get :D

    0 讨论(0)
  • 2020-11-30 04:34

    IE: JSON not defined error resolved at

    http://funkatron.com/site/comments/safely-parsing-json-in-javascript/

    by using dataType: "json" and avoid parsing

    0 讨论(0)
提交回复
热议问题