dongyi7669 2014-11-04 14:35
浏览 47
已采纳

在共享主机上使用jquery重新加载vs刷新页面

enter image description here

I am working with codeigniter and jquery. I am using ajax to send some info to a codeigniter function to perform a db operation , in order to update the page.

                  $.ajax({
                        type: "POST",
                        url: BASE_URL+"Update/update",
                        data:{ i : searchIDs, m : message },
                        dataType: 'json',
                        success: function(data) {
                            console.log(data);                              

                        },
                        error: function(data) {
                            console.log(data);
                        },
                        complete: function() {
                            alert("REFRESHING..");

                         window.location.href = "pan_controller/reply";
                        }
                });

After the operation is complete I want to reload the page. This works normally in locally on my WAMP. However when I deploy to a shared host I usually have to reload the page manually, (using the reload button in the browser -- screenshot above). I see no errors in firebug. I've tried a variety of fixes but have recently started to wonder if this is a caching issue on my shared hosting server. If so is there a better way to reload using jquery rather than just redirect so as to avoid a cache on the shared host?

  • 写回答

1条回答 默认 最新

  • dongshan4878 2014-11-04 14:40
    关注

    Have you established that the complete function is running in those cases when the page doesn't reload? If so then I think you are right, it's a caching problem.

    You can try adding a timestamp parameter to the end of the window.location.href value to make it unique each time and avoid any issues with caching, although a better approach would be to send the correct headers back with the response, so that the browser knows not to cache that page.

    window.location.href = "pan_controller/reply?t=" + (new Date().getTime());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C