[英]Echo in php Post block is not printing out values posted by JQuery
我有一個可以運行一定次數的測試的測試,完成后,它將數據發布到PHP腳本中。 數據已成功添加到數據庫,但不會回顯結果。 我希望為用戶顯示測試結果。
的PHP
<?php
require_once 'php-includes/header.php';
include ('php-includes/phpValidate.php');
if ($_POST) {
include ('php-includes/antHelper.php');
$testData = removeDelimiters($_POST['RT'], $_POST['condition'], $_POST['response'], $_POST['ansStr'], $_POST['congruency'], $_POST['cueStr']);
$testID = addTest($_POST['toa'], $_POST['nTrial']);
if (isset($testID)) {
for ($i = 0; $i < count($testData["RT"]); $i++) {
addResponse((int)$testData["RT"][$i], (int)$testData["condition"][$i], $testData["response"][$i], $testData["answer"][$i], $testData["cue"][$i], $testData["congruence"][$i], $testID);
}
$results = getCueScores($testID);
$results = getCongruencyScores($testID, $results);
$alerting = $results["noCue"] - $results["doubleCue"];
$orienting = $results["centerCue"] - $results["spatialCue"];
$executive = $results ["incongruent"] - $results["congruent"];
echo 'Your alerting result is' . $alerting;
echo 'Your orienting result is' . $orienting;
echo 'Your executive result is' . $executive;
header('Location: index.php');
}
}
?>
JS
$(".btn[name=submitANT").click(function() {
$.post("antApp.php",
{response : $("input[name=rspStr]").val(), RT : $("input[name=RTStr]").val(), nTrial : $("input[name=nTrial]").val(), toa : $("input[name=toa]").val(),
condition : $("input[name=condition]").val(), ansStr : $("input[name=ansStr]").val(), cueStr : $("input[name=cueStr]").val(),
congruency : $("input[name=congruency]").val()},
function(data) {
//$("#antDebrief").show();
//$("#antDebrief").css("visibility", "visible");
});
});
您的PHP發送header('Location: index.php');
回聲之后。
這就像一個window.location.href="XYZ";
。
它重定向頁面。
因此,也許沒有什么問題,但是您沒有時間看到回聲。
嘗試注釋此行:
header('Location: index.php');
根據評論進行編輯
1-您的“呼叫”頁面必須與“被呼叫”頁面不同。 調用自己的頁面永遠不是一件好事。
2-在您的被調用頁面(antApp.php)中,標題存在: require_once 'php-includes/header.php';
這可能是正文和頁腳: include ('php-includes/phpValidate.php');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.