在ajax post

时间:2017-08-24 09:32:31

标签: php jquery json ajax

我被要求执行ajax发布一些值到PHP脚本。当php脚本收到值并应显示值时。但是,这些值未显示在console.log上。 AJAX在哪里发布了价值?我的代码在下面找到....帖子值将在哪里发布?它会被发布在html文件或php文件上吗???

student.php

<?php
function executePass()
{

    $conn = mysqli_connect('localhost','root','netwitness') or die ("Could not connect database");
    $db = mysqli_select_db($conn,'abdpractice') or die ('Could not select database');

    $result = mysqli_query($conn,"select * from student");
    $json_array = array();
    while ($row = mysqli_fetch_assoc($result))
    {
        $json_array[] = $row;
    }

    echo json_encode($json_array);
}
?>

passwrapper.php

<?php
include 'student.php';
executePass();
receivePost();
function receivePost()
{
    if ((!isset($_REQUEST["lastName"])) and (!isset($_REQUEST["lastReligion"])))
    {
        //do nothing
    } 
    else 
    {
        echo '<script>console.log("LastRowname = '.$_POST["lastName"].' LastRowReligion = '.$_POST["lastReligion"].'");</script>';
    }
}
?>

html文件

<html>
<head>
<script type="text/javascript" src="/Cesium-1.34/ThirdParty/jquery-1.11.3.min.js"></script> 
</head>
<div id="results"</div>
<div id="resulte"</div>
<script type="text/javascript">
showData();
function showData()
{
    $.ajax({
        type: "post",
        url: "passwrapper.php",
        contentType: "application/json",
        dataType: "json",
        data: {
            lastName: 'Abdullahlahlahlah',
            lastReligion: 'Muslim',
        },      
        success: function(data){
            console.log(data);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert('An error occurred... Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information!');
            $('#resulte').html('<p>Status Code: '+jqXHR.status+'</p><p>ErrorThrown: ' + errorThrown + '</p><p>jqXHR.responseText:</p><div>'+jqXHR.responseText + '</div>');
            console.log('jqXHR:');
            console.log(jqXHR);
            console.log('textStatus:');
            console.log(textStatus);
            console.log('errorThrown:');
            console.log(errorThrown);
        },

    });
};
</script>
</body>
</html>

最初我的代码解释如下。我执行ajax post到passwrapper.php,这个脚本包含另一个脚本来显示html控制台页面上的所有数据。我被要求执行一个ajax帖子来发布一些值并获取这些值并将值发布在html上的console.log和passwrapper.php中...整个数据发布在html控制台上然而我不是能够在console.log上找到Abdullahlahlahlah和穆斯林的发布值。你能帮我解决一下如何在passwrapper.php中的console.log上显示发布的值..谢谢......

0 个答案:

没有答案