Intel Xdk - 输入错误意外结束

时间:2016-06-01 07:17:45

标签: php ajax hybrid-mobile-app intel-xdk

代码适用于chrome。但是使用Intel xdk在调试模式下出错。我不知道我的ajax代码或我的php服务器响应是否有问题。似乎它没有回复数据。

Error I got

我的php代码如下所示:

<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');


include('../../config.php');

session_start();

if(isset($_POST['input_email']) && isset($_POST['input_password'])){

            $post = $_POST;
            array_walk_recursive($post, 'clean');

        $sql = "SELECT * FROM user
                    WHERE TRIM(user_email) = '{$post['input_email']}' AND
                    (
                        TRIM(user_password) = md5('{$post['input_password']}')
                    )";
        $user = db::select_row($sql);
        $loggedinusing = 'real';//real password

        if($user['user_status'] == 'active'){
                $_SESSION['user_id'] = $user['user_id'];

        }else{
                $loggedinusing = 'unmatch';//Your username and password didn\'t match.
        }

echo json_encode($loggedinusing);
}   
 ?>

我的阿贾克斯:

$.ajax({
       type: "POST",
       url: "http://www.example.com/app/login.php",
       crossDomain: true,
       dataType: 'json',
       data: $.trim(frm.serialize()),
       beforeSend: function() {
       $('#loader').css({display: "block"});
       },
       success: function(data, status, XHR) {
           console.log("result is " + data);
           handleData(data); //use to handle the data that server had thrown
       },
       error: function(xhr, ajaxOptions, thrownError) {
           alert(xhr.statusText +" "+thrownError);
           $('#loader').css({display: "none"});
       }
});

function handleData(responseData) {
                var access = responseData;

                if (access == "real") {
                    alert("Welcome");
                    location.href = "home.html";
                    $('#loader').css({display: "none"});

                } else {
                    alert("Your username and password didn\'t match.");
                    $('#input_password').val('');
                    $('#login').attr("disabled", "disabled");
                    $('#loader').css({
                        display: "none"
                    });

               }
                console.log(responseData);
}

0 个答案:

没有答案