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>';
    
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码