$ .ajax不会在IE上触发事件,只有在页面重新加载后才能成功

时间:2013-01-10 10:31:01

标签: jquery ajax internet-explorer-9

这是我的代码:

...
$('#collection_menu ul li').click(function(e) {
  e.preventDefault();
  e.stopPropagation();

  shoesApparaissent();
});

...

function shoesApparaissent() {

  $.ajax({
    async:true,
    url : hrefCollection,
    type : 'GET',
    dataType : 'json'
  }).success(function(data) {

console.log("data: " + data);

  }).fail(function(e, str) {

console.log(e+'\n'+str);

});
...

在我重新加载包含代码的页面之前,此代码似乎可用于FF,Safari,Opera和除Windows上的IE之外的所有其他导航器。

当我触发click事件时,调用函数'shoesApparaissent()'并且$ .ajax不会触发成功或失败事件(控制台中没有任何内容)。

我不确定这里有什么问题,有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您使用的是哪个版本的jQuery?对于这个答案,我假设您将使用更新的版本,如1.8。在jQuery 1.5+中,$.ajax()方法返回一个实现Promise接口的对象。

而不是使用.success()回调(jQuery 1.8中不推荐使用),而是使用.done()

$.ajax({
    url: hrefCollection,
    type: 'GET',
    dataType : 'json'
}).done(function(data) {
    console.log("data: " + data);
}).fail(function(e, str) {
    console.log(e+'\n'+str);
});
相关问题