【发布时间】:2013-04-03 01:19:27
【问题描述】:
我和许多其他人一样遇到了 IE 和缓存问题。我有一个拍卖网站,当用户点击出价时,触发此代码:
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 (update-auction.php) 中,我得到了这个发布的 ajax 数据并更新了我的数据库:
$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+"|");
}
});
}
(触发 ajax 调用并显示第二页的 onClick)然后这个 function bid(id) 停止工作。我已经搜索了诸如cache:false, 添加new Date().time(); 以在 JSON 中发布和发布数据之类的解决方案,但没有运气。
(此外,当我尝试以 JSON 格式发布数据时,我遇到了一些语法错误:Unexpected token
【问题讨论】:
-
如何“转到第二页”?您是否正在修改 DOM,并替换具有点击处理程序的元素?然后你需要重新绑定处理程序,或者使用
.on()的委托。 -
我已经更新了帖子并添加了如何进入第二页的代码...
-
出价在
#show-category内吗? -
是的。使用 pageClick () 我将页码发布到 auctions-ajax (php 文件),它返回-回显数据库的输出(在这种情况下按页面排序),一个完整的拍卖(完整的意思是输出是用 css 和所以一个..)谢谢..
标签: internet-explorer jquery caching