weixin_33733810 2017-08-24 05:35 采纳率: 0%
浏览 23

Ajax发布值是空的

I wanted to get the data from the ajax post which are the student name and student religion(abdullah and muslim) values in the passwrapper.php and post those values on the console.log. However, i cant find the posted values on the console.log. i want to show those posted values on the console.log.

Here is my code below.... orignially my code is about performing ajax post to the passwrapper.php and then the passwrapper.php include another script, student.php to show all the data on the html file.

HTML FIle

<html>
<head>
<script type="text/javascript" src="/Cesium-1.34/ThirdParty/jquery-1.11.3.min.js"></script> 
</head>
<div id="resulte"</div>
<script type="text/javascript">
showData();
function showData()
{
    $.ajax({
        type: "post",
        url: "passwrapper.php",
        contentType: "application/json",
        dataType: "json",
        data: {
            lastName: 'Abdullah',
            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>

Passwrapper.php

    <?php
include 'student.php';
executePass();

receivePost();
function receivePost()
{
    if ((!isset($_POST["lastName"])) and (!isset($_POST["lastReligion"])))
    {
        //do nothing
    } 
    else 
    {
        echo '<script>console.log("Firstname='.$_POST["lastName"].' lastReligion='.$_POST["lastReligion"].'");</script>';

    }
}

?>

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

my question is how to post those values abdullah and muslim on the console.

  • 写回答

1条回答 默认 最新

  • weixin_33719619 2017-08-24 05:56
    关注

    try this,

    <?php
    include 'student.php';
    executePass();
    
    if ((!isset($_POST["lastName"])) and (!isset($_POST["lastReligion"])))
    {
        //do nothing
    } 
    else 
    {
        //post the values(Abdullah and Muslim) on the console.log on the passwrapper.php
        //i do not want to disrupt the executepass()
    
    echo '<script>console.log("Firstname='.$_POST["lastName"].' lastReligion='.$_POST["lastReligion"].'");</script>';
    
    }
    ?>
    
    评论

报告相同问题?