Page1.php:
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<script src="js/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function(){$("#btn_submit").click(function(){
var key = $("#key").val();
$('#mailing1').html("<a href='#' ><i class='fa fa-refresh fa-spin fa-3x fa-fw'></i> Please wait </a>");
$.post("page2.php", {key : key}, function(data){$("#mailing1").html(data)
;});});});
</script>
</head>
<body>Enter Your Key Value<input id="key" type="text">
<button id="btn_submit" type="button">Click Me!</button>
<div id="mailing1"> </div>
</body>
</html>
Page2.php:
<?php
include db.php;
echo $key=$_REQUEST[key];
$sql = mysql_query("INSERT INTO `Process`(`flags`) VALUES ($key)");
$u_id= mysql_insert_id();
echo "Process Started and the Your Unique Id is :" .$u_id;
file_get_contents("http://domain.com/page3.php?$key|$u_id");
?>
Page3.php:
<?php
include db.php;
$str =$_SERVER['QUERY_STRING'];
$str =explode("|",$str);
$key= $str[0];
$u_id= $str[1];
$sql= mysql_query("SELECT * FROM `Process` WHERE ProcessID=$u_id ");
$result= mysql_fetch_assoc($sql);
print_r($result);
if($key==1)
{
$count=0;
while($x==0)
{
$sql1 = mysql_query("SELECT flags FROM `Process` WHERE U_ID=$u_id ");
$sql2 = mysql_query("UPDATE `Process` SET count=$count WHERE U_ID=$u_id ");
$row = mysql_fetch_assoc($sql1);
$key=$row['flags'];
if ($key==1)
{echo "process runing";
echo $a=$a+1;
}
if ($key==2)
{
$x=10;
echo "process Stopped";
}
$count=$count+1;
}
}
?>
期望的输出: -
当点击我&#39;在page1.php上单击了按钮,它应该返回page2.php中的echo值(echo&#34; Process Started和你的唯一ID是:&#34;。$ u_id;)并且应该转到page3.php用于处理。
但是现在page2.php中的echo值只有在page3.php中完成所有进程后才会打印。
请给我一个可能的解决方案。
提前致谢
答案 0 :(得分:0)
Page2.php将始终等待Page3.php,因为您在脚本中调用它。
Page2.php应该返回u_id,然后在javascript代码中第二次发布到最近获得的u_id的Page3.php。
这些消息在Page2.php中无关紧要,您可以在javascript中轻松处理该部分。
因此,请删除Page2.php的这一行:
IntStream
将您的javascript代码更改为以下内容:
file_get_contents("http://domain.com/page3.php?$key|$u_id");