[英]How do you do a hard refresh with JQuery for AJAX posts?
I am using JQuery and the page acts like it refreshes but doesn't update my table. 我正在使用JQuery,页面的行为就像它刷新了一样,但是没有更新我的表。 All my other JQuery commands using the
location.reload(true);
我所有的其他JQuery命令都使用
location.reload(true);
do a hard refresh. 做一个硬的刷新。 Using this AJAX version doesn't seem to do it.
使用此AJAX版本似乎没有实现。 I plan on using the AJAX later to just update a div, but for now the whole page refresh is what I need.
我计划稍后使用AJAX来更新div,但现在需要刷新整个页面。
JS JS
$(document).ready(function(){
$('#import_audit').click(function(){
//alert("Audit Deleted");
$('#import_audit_div').modal('show'); //show modal with id="import_audit_div"
$('#import_audit_table').load("edit_audits.php?action=import"); //Doesn't load from database until modal is loaded.
});
$(function() {
$("#import_audit_form").submit(function(e) {
e.preventDefault();
// 'this' refers to this form element
var data = $(this).serialize();
$.ajax({
type: "POST",
url: "edit_audits.php?action=process_import",
data: data,
success: function (data) {
alert("Audit Transfered");
//$('#import_audit_div').modal('hide');
location.reload(true);
//trying to reload only the div
//$("#Results1").load(location.href + " #Results1");
}
});
});
});
});
You are missing a });
您缺少
});
at the bottom. 在底部。 In your browser development tools does it show an error in your console?
在浏览器开发工具中,它是否在控制台中显示错误? I don't think your javascript is actually working, which would mean that the
location.reload(true)
never fires. 我认为您的JavaScript并没有真正起作用,这意味着
location.reload(true)
永远不会触发。
I think its the ajax request itself that is cached. 我认为它是缓存的ajax请求本身。 Try adding the cache setting.
尝试添加缓存设置。
$.ajax({
type: "POST",
url: "edit_audits.php?action=process_import",
data: data,
cache : false,
...
There's some conflicting information on whether this has an effect, but it's worth trying. 关于是否有效,存在一些相互矛盾的信息,但是值得尝试。
cache (default: true, false for dataType 'script' and 'jsonp') Type: Boolean If set to false, it will force requested pages not to be cached by the browser. cache(默认值:true,对于dataType'script'和'jsonp',则为false)类型:Boolean如果设置为false,将强制浏览器不缓存请求的页面。 Note: Setting cache to false will only work correctly with HEAD and GET requests.
注意:将缓存设置为false只能与HEAD和GET请求一起正常使用。 It works by appending "_={timestamp}" to the GET parameters.
它通过在GET参数后附加“ _ = {timestamp}”来工作。 The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.
对于其他类型的请求,不需要此参数,但在IE8中,当对GET已请求的URL进行POST时,则不需要该参数。
You could also try to globally disable the cache to see if that changes anything. 您也可以尝试全局禁用缓存,以查看是否有任何变化。
$.ajaxSetup({ cache: false }); $ .ajaxSetup({cache:false});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.