ajax请求没有收到响应

时间:2013-09-02 00:18:17

标签: php javascript ajax

我不知道为什么我的ajax请求没有从我的服务器返回一个值而且它让我疯狂:(

有人能说出我做错了吗?

我的ajax功能:

function ajaxObj(meth, url) {
    var x = new XMLHttpRequest();
    x.open(meth, url, true);
    x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    return x;
}


function ajaxReturn(x){
    if(x.readyState == 4 && x.status == 200){
    return true;    
    }
}

我的服务器请求:

function gebi(x){
    return document.getElementById(x);
}

function checkEmail() {
            var email = gebi("email").value;
            if (email != "") {
                gebi("emailStatus").innerHTML = '<img src="images/loading.gif">';
                var ajax = ajaxObj("POST", "signup.php");
                ajax.onreadystatuschange = function () {
                    if(ajaxReturn(ajax) == true) {
                        gebi("emailStatus").innerHTML = ajax.responseText;
                    }
                }
                ajax.send("checkEmail="+email)
            }
        }

和服务器端处理:

//EMAIL CHECK
if(isset($_POST["checkEmail"])) {
    include_once("includes/db_connect.php");
    $email = $_POST['checkEmail'];
    $sql = "SELECT user_id FROM users WHERE user_email='$email' LIMIT 1";
    $query = mysqli_query($db_connect, $sql);
    $numrows = mysqli_num_rows($query);
    if ($numrows < 1) {
        echo '<strong style="color:#009900;">OK</strong>';
        exit();
    } else {
        echo '<strong style="color:#F00;">Already exists</strong>';
        exit();
    }
}

0 个答案:

没有答案