用户注册注册错误

时间:2013-10-17 01:36:20

标签: javascript php jquery ajax mysqli

我正在创建一个网站,我有一个signup.php页面,用户可以在其中注册并将其信息输入mysqli数据库。当我这样做时,我几乎就在那里,我只是在这一行上遇到问题:

        ajax.send("&u="+u+"&e="+e+"&p="+p1+"&g="+g);

它基本上是在ajax / javascript检查中发送变量,以便为传输到服务器做好准备。但我在该行收到内部服务器500错误。有任何想法吗?如果你想要我,我会发布更多代码。

function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
    return true;
}
}
function signup(){
var u = _("username").value;
var e = _("email").value;
var p1 = _("pass1").value;
var p2 = _("pass2").value;
var g = _("gender").value;
var status = _("status");
if(u == "" || e == "" || p1 == "" || p2 == "" || g == ""){
    status.innerHTML = "Fill out all of the form data";
} else if(p1 != p2){
    status.innerHTML = "Your password fields do not match";
}  else {
    _("signupbtn").style.display = "none";
    status.innerHTML = 'please wait ...';
    var ajax = ajaxObj("POST", "signup.php");
    ajax.onreadystatechange = function() {
        if(ajaxReturn(ajax) == true) {
            if(ajax.responseText != "signup_success"){
                status.innerHTML = ajax.responseText;
                _("signupbtn").style.display = "block";
            } else {
                window.scrollTo(0,0);
                _("signupform").innerHTML = "OK "+u+", check your   email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you       successfully activate your account.";
            }
        }
    }
    type:post;
    ajax.send("&u="+u+"&e="+e+"&p="+p1+"&g="+g);
}

}

1 个答案:

答案 0 :(得分:1)

500内部服务器错误代码是一个HTTP响应代码,表示您已经联系到服务器并且它已响应并显示错误。所以它似乎不是你的JS代码的问题(至少就我们从你发布的内容中可以看出来而言)。

尝试将var_dump($_REQUEST); die();作为signup.php的第一行。这会给你一个200状态代码吗?如果是这样,请尝试将该行向下移动到服务器上的代码中,直到您返回到500内部服务器错误,并且您已找到导致问题的行。


您有使用jQuery标记的问题,但我在您的代码示例中没有看到任何jQuery。如果你有,试试这个:

function signup() {
    var status = $('#status');
    var signupbtn = $('#signupbtn');
    var data = {
        u: $('#username').val(),
        e: $('#email').val(),
        p: $('#pass1').val(),
        g: $('#gender').val()
    };

    if (data.u == '' || data.e == '' || data.p == '' || data.g == '') {
        status.text('Fill out all of the form data');
        return;
    } else if (data.p != $('#pass2').val()) {
        status.text('Your password fields do not match');
        return;
    }

    signupbtn.hide();
    status.text('please wait...');

    $.ajax({
        type: 'post',
        url: 'signup.php',
        data: data,
        success: function(responseText) {
            if (responseText != 'signup_success') {
                status.text(responseText);
                signupbtn.show();
                return;
            }

            window.scrollTo(0, 0);
            $('#signupform').html('OK '+ data.u +', check your email inbox and junk mail box at <u>'+ data.e +'</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.');
        },
    });
}