2013-04-11 74 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

相關問題