在刷新浏览器

时间:2016-02-29 06:42:30

标签: javascript php html perl localhost

希望我能清楚地说出我的问题。 我在我的localhost上开发了一个应用程序,其中包含用于界面的HTML文件以及用于该功能的javascript,PHP,Perl文件。 界面上有一个按钮,应该将用户输入提交给其他文件,然后显示结果。 单击该按钮时,结果会在很长一段时间后生成。我现在发现当我单击该按钮然后刷新页面时,结果就会生成! 似乎结果正在等待中。 此外,当我单击该按钮并在浏览器中打开另一个选项卡并打开另一个localhost应用程序时,虽然两个应用程序不同,但仍会生成结果。

HTML:

<input type='button' value='search' onclick="jsFunction(document.getElementsByName('x1')[0].value,document.getElementById('x2').options[document.getElementById('x2').selectedIndex].value);">

JAVASCRIPT:

function jsFunction(x1,x2) 
{
    var url = "file.php";
    var params = "x1="+x1+"&x2="+x2;
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() 
    {
        if (xhttp.readyState == 4 && xhttp.status == 200) 
          document.getElementById("result").innerHTML = xhttp.responseText;
        }
xhttp.open("POST", url, true);
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhttp.send(params);
}

file.php:

$x1= (empty($_POST['x1'])) ? '' : $_POST['x1'];
$x2= (empty($_POST['x2'])) ? '' : $_POST['x2'];
echo "This echo before perl statement    ";
pclose(popen("start /b perl file.pl \"$x1\" \"$x2\"", "r"));
echo "This echo after perl statement";

显示以上两个回声。

Perl file.pl:调用cmd应用程序并在文件中生成结果

open LOG, ">$dataPath/$jobid.log";
open OUT1, ">$dataPath/$jobid.string.txt";
open OUT2, ">$dataPath/$jobid.result.txt";

在刷新浏览器或生成需要很长时间后才会生成上述perl结果。

非常感谢任何澄清或帮助。 感谢。

1 个答案:

答案 0 :(得分:2)

start /b perl file.pl "$x1" "$x2"命令将立即返回perl进程已启动。它不会等待它完成

要等待perl进程完成,您需要使用

start /b /wait perl file.pl "$x1" "$x2"

但是,你所有的Perl代码似乎都是创建三个磁盘文件然后退出

相关问题