internet-explorer - 在 Internet Explorer 中第二次调用后 jQuery ajax 不工作

标签 internet-explorer jquery caching

像许多其他人一样,我也遇到了 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+"|");
        }
    });

}

(onClick 会触发 ajax 调用并显示第二页),然后此函数 bid(id) 停止工作。我搜索过类似 cache:false, 添加 new Date().time(); 来以 JSON 格式发布和发布数据的解决方案,但没有成功。 (此外,当我尝试以 JSON 格式发布数据时,我遇到了一些语法错误:意外的标记 < 和解析错误等等)。我只是想用这个工作代码找出最简单的解决方案......有什么想法吗?

最佳答案

这解决了我的问题:

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

“原因是,有些浏览器只要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
    //});
}

关于internet-explorer - 在 Internet Explorer 中第二次调用后 jQuery ajax 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15938737/

相关文章:

javascript - 在 jQuery 加载命令之后,有没有办法强制等待,直到 html 渲染到 div 中?

java - 基于微服务的架构和每个节点的单独缓存

jquery - 为什么选择下拉菜单不允许我单击某个项目 IE,但在 Firefox、Chrome 等中却可以正常工作?

javascript - 在某些情况下,通过 Javascript 加载 HTML 内容会使我的 &lt;title&gt; 标签无效

javascript - 如何在旧版 IE 中调度鼠标滚轮事件

javascript - 使用jQuery根据Input隐藏父元素

jquery:复制并粘贴html

internet-explorer - 如何将ActiveX控件转换为NPAPI插件

ruby-on-rails - Scraping rake 任务似乎受到不需要的缓存的影响

javascript - 找不到在离线 Web 应用程序中存储用于离线下载的文件的方法