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

标签 javascript php jquery html ajax

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

我想要 html 格式 1-在某个div中显示处理语句。//这就成功了 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 echo?

注意: 我的系统行为:

  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>

关于javascript - 如何在不同的html div中的php文件中显示不同的回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35611278/

相关文章:

jquery - 根据内容 Bootstrap 井大小

jQuery:有一种方法可以将颜色(色调)应用于图像吗?

javascript - 如果 div 位于特定位置之上,则仅重新加载页面一次

javascript - 使用 if 语句调用函数

javascript - 将事件注册到新添加的选择器

php - 在 MAC OSX 上的 XAMPP 中更新 PHP

php - 我如何确保我捕捉到来自 MySQLi::multi_query 的所有错误?

javascript - InDesign 脚本 : How to print specific spot color in separations?

javascript - 仅使用 Javascript 将 PHP 对象转换为 JSON 对象

php - 插入语句不起作用。不转移到其他表