简体   繁体   English

ajax 中的成功 function 未在控制台中返回任何内容

[英]Success function in ajax not returning anything in console

Here is my code, and while running it's not giving anything in the console.这是我的代码,在运行时它没有在控制台中提供任何内容。

This is how I am trying to check the data.这就是我试图检查数据的方式。 If the data correctly I want the mentioned console in success code.如果数据正确,我希望在成功代码中提到提到的控制台。 But if it is not then I want else code to run.但如果不是,那么我希望运行其他代码。 But the if-else conditions are not working properly.但是 if-else 条件无法正常工作。 I am including PHP code and ajax code which I have tried.我包括我尝试过的 PHP 代码和 ajax 代码。 Am I doing it right?我做对了吗?

<?php
    $host = "dpydaldermt01.******.com";
    $username = "test";
    $password = "Test";
    $database_name = "test";
    $conn = mysqli_connect($host, $username, $password, $database_name) or die("Connection failed: " . mysqli_error());

    $sql = "select ID, user_email from ci_iwp_wp_users limit 10";

    $result = mysqli_query($conn, $sql);
    $users = array();
?>
<script>
    (function($) {
    <?php
    while($row = mysqli_fetch_assoc($result)) {
        $email =  $row['user_email'];
    ?>
        var mail = "<?php echo $email ?>";
        $.ajax({
            type:'POST',
            url:'http://bluepages.ibm.com/BpHttpApisv3/wsapi?byInternetAddr='+mail,
            dataType:'someData',
            success: function(data) {
                if(data === '# rc=0, count=0, message=Success') {
                    console.log(data);
                }
            }
        });
    <?php
        $users[]=$row;
    }
    ?>
    });
</script>
<?php
    echo json_encode($users);
?>

Just Remove dataType:'someData', from your code because it always request and response in json so you dont have to declare separately.只需从您的代码中删除 dataType:'someData',因为它总是在 json 中请求和响应,因此您不必单独声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM