Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 正在等待慢速重定向消息_Ajax_Submit_Message - Fatal编程技术网

Ajax 正在等待慢速重定向消息

Ajax 正在等待慢速重定向消息,ajax,submit,message,Ajax,Submit,Message,我有以下代码: <?PHP if (isset($_POST['submit'])) { header("Location: http://mysite.com"); } ?> <form name="form1" action="" method="post"> Name: <input name="name" type="text"> <input type="submit" value="submit" name=

我有以下代码:

<?PHP

  if (isset($_POST['submit'])) {
    header("Location: http://mysite.com");
  }

?>

<form name="form1" action="" method="post"> 
  Name: <input name="name" type="text"> 
  <input type="submit" value="submit" name="submit">
</form>

姓名:
问题是,当我提交表单时,重定向到mysite.com的时间太长,需要5-10秒。 我想显示一个信息“正在加载…请稍候”och显示一个动画图像,这样我就知道发生了什么事


如何使用javascript och ajax?

我不知道这是否可能(但我不这么认为),但您可以添加exit();在设置标题后,脚本的其余部分不会执行并发送到浏览器。这样可以减少一点时间

您可以尝试使用javascript而不是http头进行重定向

<?php if (isset($_POST['submit'])): ?>
<script>
  alert('Loading... Please wait');
  document.location.href = 'http://mysite.com';
</script>
<?php endif; ?>

警报(“正在加载…请稍候”);
document.location.href=http://mysite.com';

你应该有这样的东西 加载过程会一直移动图像GIF,直到ajax请求结束,然后加载过程就会隐藏 其中result在屏幕上显示数据库结果网格搜索

<tr valign="top">
        <td id="results" colspan="8" align="center" width="100%" height="250px">
    </td>
</tr>

<tr valign="top" id="loading" style="display:none;">
    <td colspan="8" width="100%" align="center">
      <img name="loading_image" src="images/loading.gif" border="0" width="214" height="200">
    </td>
</tr>

5-10秒提交页面。首先,试着弄清楚为什么要花那么多时间

无论如何,如果您只想在按下submit按钮时看到一些消息,那么只需添加任何div(初始隐藏)。点击submit按钮可以显示这个div

请参见示例代码:

<?PHP

  if (isset($_POST['submit'])) {
    header("Location: http://mysite.com");
  }

?>

 <div id='loadingDIV' style='display: none;'></div>

<form name="form1" action="" method="post"> 
  Name: <input name="name" type="text"> 
  <input type="submit" value="submit" name="submit" onclick='showLoadingAndSubmit();'>
</form>
<?PHP

  if (isset($_POST['submit'])) {
    header("Location: http://mysite.com");
  }

?>

 <div id='loadingDIV' style='display: none;'></div>

<form name="form1" action="" method="post"> 
  Name: <input name="name" type="text"> 
  <input type="submit" value="submit" name="submit" onclick='showLoadingAndSubmit();'>
</form>
    function showLoadingAndSubmit(){
        document.getElementById ('loadingDIV').innerHTML = 'Form submitting. Please wait...';
document.getElementById ('loadingDIV').style.display = 'block';
        return true;
    }