2013-04-11 80 views
1

我有像许多其他人一样的问题,IE和可能的缓存。我有一个拍卖网站,当用户点击竞价,火灾这段代码在Internet Explorer中第二次调用后jQuery ajax不工作

function bid(id){ 
var end_dateUP=0; 

var tupdate=jq("#tupdate"+id).val(); 

if (tupdate=="lvl1"){ 
    end_dateUP=20; 
}else if (tupdate=="lvl2"){ 
    end_dateUP=15; 
}else if (tupdate=="lvl3"){ 
    end_dateUP=10; 
}else{ 
    end_dateUP=0; 
} 

var url = "http://localhost/bid/comet/update-auction.php"; // the script where you handle the form input. 
var user_id=<?php echo json_encode($user_id);?>; //here i'm getting id from SESSION 
var user_name=<?php echo json_encode($user_name); ?>; //here i'm getting user name from SESSION 
jq.ajax({ 
    type: "POST", 
    async: false, 
    url: url, 
    data: {"auct_id" : id, "user_id" : user_id, "username" : user_name, "end_date" : end_dateUP}, // serializes the form's elements. 
    cache:false, 
    success: function(data) 
    { 
     setTimeout('waitForMsg()',100); 
     jq("#tupdate"+id).val(""); 
     jq('#bid-container'+id).animate({ backgroundColor: "#659ae0" }, 50); 
     jq('#bid-container'+id).animate({ backgroundColor: "#FFF" }, 500); 

    }, 
    error: function(xhr, errorString, exception) { 
     alert("xhr.status="+xhr.status+" error="+errorString+" exception=|"+exception+"|"); 
    } 
}); 
} 

和PHP(更新auction.php)我得到这个贴阿贾克斯数据和更新我的数据库:

$auction_id=$_POST['auct_id']; 
$user_id=$_POST['user_id']; 
$usr=$_POST['username']; 
$enddate=$_POST['end_date']; 


//Database update 

此代码在Firefox或Chrome中非常适用。
所以问题是,当我点击出价第一次,它的工作原理,但是当我去到第二页(下面的代码):

function pageClick(page){ 
var url = "http://localhost/bid/auctions-ajax"; // the script where you handle the form input. 

jq.ajaxSetup({ cache: false }); //this line before $.ajax!!! 
    jq.ajax({ 
      type: "POST", 
      url: url, 
      data: {"page" : page}, 
      async:false, //to sem dodal za časovni zamik 
      cache: false, 
      success: function(data) 
      { 
      jq("#a_loader").hide(); 
      jq("#show-category").html(data); // show response from the php script.    
      }, 
      error: function(xhr, errorString, exception) { 
      alert("xhr.status="+xhr.status+" error="+errorString+" exception=|"+exception+"|"); 
     } 
    }); 

} 

(的onClick它将触发Ajax调用并显示第二页)那么function bid(id)停止工作。我搜索了像cache:false,这样的解决方案,并添加了new Date().time();来发布和发布JSON数据,但没有运气。 (另外当我试图以JSON格式发布数据时,我遇到了一些语法错误:意外的令牌<和解析错误等等)。我只是试图找出这个工作代码的最简单的解决方案...任何想法?

+0

你是如何 “去第二页”?你是否在修改DOM,并替换具有点击处理程序的元素?然后,您需要重新绑定处理程序,或者使用'.on()'使用委托。 – Barmar 2013-04-11 00:26:36

+0

我已更新帖子并添加了代码,我如何转到第二页... – 2013-04-11 00:31:19

+0

是否在'#show-category'内出价? – Barmar 2013-04-11 00:40:42

回答

0

好的,我找到了解决方案。 Internet Explorer有jQuery动画问题。我有一个老的,这是造成问题,并没有完全执行脚本。我必须包含最新的<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>才能在IE中工作。现在效果很好。

0

如果您目前正在结合单击处理有:

$("selector").click(function...); 

将其更改为:

$("#show-category").on("click", "selector", function ...); 

这是必要的,因为pageClick()取代了之前所具有的点击绑定的DOM元素。您需要使用在页面替换中保留的父元素的委派。

+0

嗯..但我没有像你说的“点击”功能 - >'$(“selector”)。click(function ...);'。这个页面在auctions-ajax php文件中被调用,如下所示:在这个例子中''到第一页。然后这个'function pageClick(page)'执行...谢谢你的帮助! – 2013-04-11 10:39:13

+0

这是进入下一页的代码。你如何约束功能点击出价,这也是'onclick'?您使用AJAX加载的HTML中的绑定? – Barmar 2013-04-11 10:43:58

+0

是的,也在ajax - > auctions-ajax php文件中。当我点击BID按钮'BID'时,它会触发此javascript'功能出价(id)' – 2013-04-11 11:29:56

1

这解决了我的问题:

$.ajax(url, 
{ 
cache: false, 
success: function(){ 
//do something 
} 
} 
); 

“的原因是,一些浏览器CACH的结果,只要请求是GET请求一样的。”

例子:

function showBootstrapModalPopup(url, containerId, modalId) 
{ 
     $.ajax(url, 
     { 
      cache: false, 
      success: function (data) { 
       //do something 
       $('#' + containerId).html(data); 

       $('#' + modalId).modal('show'); 
      } 
     } 
     ); 


    //$.ajax({ 
    // url: url, 
    // success: function (data) { 
    //  $('#' + containerId).html(data); 

    //  $('#' + modalId).modal('show'); 
    // }, 
    // cache: false 
    //}); 
} 
+1

它解决了我的问题。谢谢 – adnan 2018-02-27 10:49:29

相关问题