简体   繁体   English

PHP Post块中的Echo无法打印出JQuery发布的值

[英]Echo in php Post block is not printing out values posted by JQuery

I have a test that runs for a certain number of trials, and once finished, it posts the data to the PHP script. 我有一个可以运行一定次数的测试的测试,完成后,它将数据发布到PHP脚本中。 The data is successfully added to the database, but it does not echo out the results. 数据已成功添加到数据库,但不会回显结果。 I want the test results to be displayed for the user. 我希望为用户显示测试结果。

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

You PHP sends header('Location: index.php'); 您的PHP发送header('Location: index.php'); right after the echos. 回声之后。

This is like a window.location.href="XYZ"; 这就像一个window.location.href="XYZ"; .
It redirects the page. 它重定向页面。
So maybe there is nothing wrong but you just don't have the time to see the echos. 因此,也许没有什么问题,但是您没有时间看到回声。

Try commenting this line : 尝试注释此行:

header('Location: index.php');

EDIT based on comment 根据评论进行编辑

1- Your "calling" page has to be different than the "called" page. 1-您的“呼叫”页面必须与“被呼叫”页面不同。 A page that calls itself is never a good thing. 调用自己的页面永远不是一件好事。

2- in your called page (antApp.php), the header is present : require_once 'php-includes/header.php'; 2-在您的被调用页面(antApp.php)中,标题存在: require_once 'php-includes/header.php'; and this is probably the body and footer : include ('php-includes/phpValidate.php'); 这可能是正文和页脚: include ('php-includes/phpValidate.php');

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

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