Ajax发布值是空的 [英] ajax post values is empty

查看:62
本文介绍了Ajax发布值是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ajax帖子中获取数据,这些数据是passwrapper.php中的学生姓名和学生宗教(阿卜杜拉和穆斯林)值,并将这些值发布到console.log上.但是,我在console.log上找不到发布的值.我想在console.log上显示那些发布的值.

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.

这是我的下面的代码... 原始地,我的代码是关于将ajax发布到passwrapper.php 然后passwrapper.php包含另一个脚本Student.php,以显示html文件中的所有数据.

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文件

<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

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

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

我的问题是如何在控制台上发布这些值abdullah和穆斯林.

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

推荐答案

尝试一下,

<?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>';

}
?>

这篇关于Ajax发布值是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆