我有像許多其他人一樣的問題,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格式發佈數據時,我遇到了一些語法錯誤:意外的令牌<和解析錯誤等等)。我只是試圖找出這個工作代碼的最簡單的解決方案...任何想法?
你是如何 「去第二頁」?你是否在修改DOM,並替換具有點擊處理程序的元素?然後,您需要重新綁定處理程序,或者使用'.on()'使用委託。 – Barmar 2013-04-11 00:26:36
我已更新帖子並添加了代碼,我如何轉到第二頁... – 2013-04-11 00:31:19
是否在'#show-category'內出價? – Barmar 2013-04-11 00:40:42