-1

我使用jQuery和ajax,它可以在除IE 9或更早版本以外的所有浏览器中工作。 jQuery本身的作品,但不是ajax调用。我使用下面的代码:jQuery Ajax无法在IE 9或更高版本中工作

HTML:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 

JS:

if ($('#page-home').length) { 
    var $targetDivOffers = $('#results-recent-offers'); 

    var query = {}; 
    query = { 
     status: 'all', 
     category: 'all', 
     limit: 3 
    }; 

    // first load recent gesuche 
    query.type = 1; 

    $targetDivOffers.html(''); 

    $.ajax({ 
     type: "POST", 
     url: "system/process-get-adverts.php", 
     data: query, 
     dataType: 'JSON', 
     cache: false 
    }).done(function (html) { 
     $('.ajax-loader').show().delay(300).promise().done(function() { 
      $('.ajax-loader').fadeOut().promise().done(function() { 
       $targetDivOffers.html(html.results); 
      }); 
     }); 
    }).fail(function (jqxhr, textStatus, error) { 
     var err = textStatus + ", " + error; 
     $targetDivOffers.html("Request Failed: " + err); 
     }); 
} 

可能是有关于我的代码,使得它不是在IE9或旧的工作是什么?

UPDATE

我试图minimalize我的代码,以便检查,如果我jQuery的集成正常。以下代码在IE 9或更低版本中仍然不起作用:

<!doctype html> 
<!--[if lt IE 7]> 
<html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]--> <!--[if IE 7]> 
<html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]--> <!--[if IE 8]> 
<html class="no-js lt-ie9" lang=""> <![endif]--> <!--[if gt IE 8]><!--> 
<html class="no-js" lang=""> <!--<![endif]--> 

<head> 
    <meta title="Test"> 
</head> 

<body> 

<p id="test"></p> 

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="assets/js/jquery-1.11.1.min.js.js"><\/script>')</script> 

<script type="text/javascript"> 
    $.ajax({ 
     url: 'http://api.joind.in/v2.1/talks/10889', 
     data: { 
      format: 'json' 
     }, 
     error: function() { 
      $('#info').html('<p>An error has occurred</p>'); 
     }, 
     dataType: 'jsonp', 
     success: function (data) { 
      var $title = $('<h1>').text(data.talks[0].talk_title); 
      var $description = $('<p>').text(data.talks[0].talk_description); 
      $('#test') 
       .append($title) 
       .append($description); 
     }, 
     type: 'GET' 
    }); 
</script> 

</body> 

</html> 

此代码有什么问题?

+2

你正在使用哪个版本的jQuery? – Tushar

+0

究竟发生了什么问题?您是否检查过开发者控制台是否有错误? – Pointy

+1

“不工作”不是一个有用的问题描述。您在F12 Dev Tools中看到了哪些错误?打电话只是不完全?完成并调用'失败'?设置你的电脑着火? –

回答

0

这可能是Jquery无法正确加载。 尝试如下:

<!--[if lt IE 9]> 
    <script src="jquery-1.9.0.js"></script> 
<![endif]--> 
<!--[if (gte IE 9) | (!IE)]><!--> 
    <script src="jquery-2.0.0.js"></script> 
<!--<![endif]--> 

另一个原因可以是jQuery的/ IE不正确地进行urlencode双引号和示出了URL( “”)而不是已编码双引号(%22)。

+0

我试过了,但这也没有奏效。 \t 我已更新我的代码。我创建了一个测试文件。上面的代码在我的后期STILL结束时不适用于IE 9或更低版本。 – Max

相关问题