jquery: window.location.reload() doesn't allow to work $.post()
look at this script please
$("#change").click(function()
{
var val = $("#new_title").val();
if(val == '')
{
alert("Նշեք խնդրեմ անունը");
return false;
}
else
{
$.post
(
"change_title.php",
{id: id, lang: lang, val: val}
);
window.location.reload();
}
});
where id
and lang
are global variables.
in change_title.php i'm uploading the table.
i want to show changes after editing, so i use window.location.reload();
function, but it doesn't work. if i delete window.location.reload();
function, it works fine.
what is the problem?
开发者_如何学JAVAThanks
You need to run it after the $.post()
completes, like this:
$.post("change_title.php",
{id: id, lang: lang, val: val},
function() {window.location.reload(); });
Without doing this as the callback to $.post()
(this runs when it completes), the window is leaving the page before the POST completes. If you don't need to do anything else in that function, you can shorten it down to:
$.post("change_title.php",
{id: id, lang: lang, val: val},
window.location.reload);
You need to use a timeout on window.location.reload
or use a callback function. The post isn't being given enough time to be sent.
精彩评论