简体   繁体   中英

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. I am including PHP code and ajax code which I have tried. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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