简体   繁体   English

如何在不同的html div中的php文件上显示不同的回声

[英]How to display different echos at php file in different html div

I have 2 files: html and php. 我有2个文件:html和php。 HTML file send variables to php via javascript. HTML文件通过javascript将变量发送到php。 PHP call perl file to 1- process the data. PHP调用perl文件以1-处理数据。 2- Then present the result in some <table><tr><td> . 2-然后将结果显示在<table><tr><td>

I want in html 1- display the processing statement in some div. 我想在html 1-中显示div中的处理语句。 //This done successfuly 2- display the result in another div. //这成功完成了2-在另一个div中显示结果。 //How to do it? //怎么做?

javascript function
{
   var url = "file.php";
   var params = //some parameters;
   var xhttp = new XMLHttpRequest();
   xhttp.onreadystatechange = function() 
{
    if (xhttp.readyState == 4 && xhttp.status == 200){
    document.getElementById("ProcessingDiv").innerHTML = xhttp.responseText;     //This div show text about processing the data.

    document.getElementById("ResultDiv").innerHTML = //How to do this?
                }
        };
       xhttp.open("POST", url, true);
       xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       xhttp.send(params);
    }

some code of PHP file: PHP文件的一些代码:

// some echo "processing data statement" here are displayed in ProcessingDiv

// statement which execute perl is here (the process takes 10 min and generate some files)

//I want below echos to displayed in ResultDiv

if(!file_exists($filename)) {
    echo "<p>No comparison meets cutoff criterion. </p>";
    }else {
    echo "<p><table border = 1 width=100% class='sortable'>";
    echo "<thead><tr><th>Query</th><th>Subject</th><th>Score</th</tr>  </thead>";
    echo "<tbody>";
    if($i == 0) {
        echo "<tr><td>$element[1]</td><td><input type='checkbox'>$target_name</td><td>$element[3]</td><td>$element[4]</td></tr>";
    }else{
                  //another echo
    }

Is that possible to display php echos in two different div? 有可能在两个不同的div中显示php echo吗?

Note: My system behaviour: 注意:我的系统行为:

  1. The browser load the HTML file which takes input from the user and send form inputs to php file by click some button. 浏览器加载HTML文件,该HTML文件从用户处获取输入,然后通过单击某些按钮将表单输入发送到php文件。

  2. When the button is clicked It displays all the echos in php "before calling perl file" in ProcessingDiv. 单击该按钮时,它将在ProcessingDiv中的“调用perl文件之前”中显示php中的所有回显。 But after excuting the perl, How do display other echos in another div? 但是在执行了perl之后,如何在另一个div中显示其他回声?

Note I try using: 注意我尝试使用:

jQuery.ajax({
       type: "POST",
        url: "blastresult.php",
        data:params,
        dataType: "html",
        success: function(data)
        {
            jQuery('#result').html(data);

        }
    });

And it do the same job. 它做同样的工作。 Presenting echoes before perl execution. 在perl执行之前呈现回显。

Hope you getting my point. 希望你明白我的意思。 Any help is highly appreciated. 任何帮助都非常感谢。 Thanks, 谢谢,

Use Ajax to display php echo on your html page: 使用Ajax在您的html页面上显示php echo:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

<script type="text/javascript">
function displayOutput()
{
    var dataString = "name=abc&gender=male";
    $.ajax({
        type: "POST",
        url: "file.php",
        data: dataString,
        dataType: "html",
        success: function(data)
        {
            $('#myDiv').html(data);

        }
    });

}

</script>

I solve the problem by seplit the response text: 我通过分隔响应文本来解决问题:

var xhttp = new XMLHttpRequest();
   xhttp.onreadystatechange = function() 
{
    if (xhttp.readyState == 4 && xhttp.status == 200){
    var parts = xhttp.responseText.split("--seperator---");
    document.getElementById("ProcessingDiv").innerHTML = parts[0];
    document.getElementById("ResultDiv").innerHTML = parts[1];
                }

Thanks everyone. 感谢大家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM