[英]How to divide the results of two different echos in two different html elements by using AJAX
[英]How to display different echos at php file in different html div
我有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嗎?
注意:我的系統行為:
瀏覽器加載HTML文件,該HTML文件從用戶處獲取輸入,然后通過單擊某些按鈕將表單輸入發送到php文件。
單擊該按鈕時,它將在ProcessingDiv中的“調用perl文件之前”中顯示php中的所有回顯。 但是在執行了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];
}
感謝大家。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.