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



我有2个文件:html和php。HTML文件通过javascript将变量发送到php。PHP 调用 perl 文件 到1-处理数据。2-然后在一些<table><tr><td>中呈现结果。

我想要在 html 中1-在某个分区中显示处理语句。2-在另一个div中显示结果。

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

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
    }

是否可以在两个不同的div中显示php回声?

注意:我的系统行为:

  1. 浏览器加载HTML文件,该文件从用户那里获取输入,并通过单击某个按钮将表单输入发送到php文件。

  2. 当按钮被单击时,它会在 ProcessingDiv 中显示 php 中的所有回声"在调用 perl 文件之前"。但是在执行 perl 之后,如何在另一个div 中显示其他回声?

注意我尝试使用:

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

它做同样的工作。在 perl 执行之前呈现回声。

希望你明白我的意思。任何帮助都非常感谢。谢谢

使用 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>

我通过分离响应文本来解决问题:

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];
                }

谢谢大家。

最新更新