duananyantan04633 2016-06-29 00: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-29 02: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');

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

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思