jQuery:window.location.reload()不允许工作$ .post() [英] jquery: window.location.reload() doesn't allow to work $.post()

查看:169
本文介绍了jQuery:window.location.reload()不允许工作$ .post()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看一下这个脚本

$("#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();
  }
 });

其中idlang是全局变量.

在change_title.php中,我正在上表.

in change_title.php i'm uploading the table.

我想在编辑后显示更改,所以我使用了window.location.reload();功能,但是它不起作用.如果我删除window.location.reload();函数,它将正常工作.

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.

出什么问题了?

谢谢

推荐答案

您需要在$.post()完成后运行它,如下所示:

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(); });

不执行此操作作为对 $.post() 的回调(此操作将在完成时运行) ,则窗口将离开POST完成之前的 页面.如果您不需要在该功能中执行任何其他操作,则可以将其缩短为:

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);

这篇关于jQuery:window.location.reload()不允许工作$ .post()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆