duananyantan04633 2016-06-28 16:10
浏览 20
已采纳

php Post块中的Echo没有打印出JQuery发布的值

I have a test that runs for a certain number of trials, and once finished, it posts the data to the PHP script. 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
    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");
            });
        });

展开全部

  • 写回答

1条回答 默认 最新

  • dougong7850 2016-06-28 18:43
    关注

    You PHP sends header('Location: index.php'); right after the echos.

    This is like a 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. 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'; and this is probably the body and footer : include ('php-includes/phpValidate.php');

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥30 SD中的一段Unet下采样代码其中的resnet是谁跟谁进行残差连接
  • ¥15 Unet采样阶段的res_samples问题
  • ¥60 Python+pygame坦克大战游戏开发实验报告
  • ¥15 R语言regionNames()和demomap()无法选中中文地区的问题
  • ¥15 Open GL ES 的使用
  • ¥15 我如果只想表示节点的结构信息,使用GCN方法不进行训练可以吗
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程