jQuery Ajax-没有成功

success in my AJAX call doesn't trigger at all, and I can't figure out why. None of the alerts specified in the AJAX file are popping up.

The form:

<form onsubmit="check_reg();return false;" method="post" name="reg_form" id="reg">
    <label class="error" id="reg_error"></label>
    <label for="login_reg">Login</label>
    <input type="text" name="login" id="login_reg" placeholder="Login">
    <label for="email_reg">Email</label>
    <input type="text" name="email" id="email_reg" placeholder="Email">
    <label for="haslo_reg">Password</label>
    <input type="password" name="password" id="pass_reg" placeholder="Password">
    <button type="submit">Register</button>  
</form>

reg_script.php:

if (!empty($_POST['login']) && !empty($_POST['password']) && !empty($_POST['email'])) {
    $login = $mysqli->real_escape_string($_POST['login']);
    $password = $mysqli->real_escape_string($_POST['password']);
    $email = $mysqli->real_escape_string($_POST['email']);

    if ($mysqli->query("INSERT INTO users (login, password, email) VALUES('$login', '$password', '$email')")) {
        echo "ok";
    } 
    else {
        echo "error";
    }
} 
else {
    echo "empty";
}

AJAX

function check_reg() {
    $.ajax({
        url: 'reg_script.php',
        type: "POST",
        data: "login=" + $('#login_reg').val() + "&password=" + $('#pass_reg').val() + "&email=" + $('#email_reg').val(),
        success: function(result) {
            if (result == 'ok') {
                alert('ok');
            }
            else if (result == 'error') {
                alert('error');
            }
            else if (result == 'empty') {
                alert('empty');
            }
        },
    });
}

Any ideas what the problem might be?

EDIT: I should've added that I used this tutorial: http://developertips.net/post/display/web/3/dynamic-login-form-with-ajax-php/ and managed to get the login form working just fine, it's just the registration form that's acting up.

Change

<form onsubmit="check_reg();return false;" method="post" name="reg_form" id="reg">
<label class="error" id="reg_error"></label>
<label for="login_reg">Login</label>
<input type="text" name="login" id="login_reg" placeholder="Login">
<label for="email_reg">Email</label>
<input type="text" name="email" id="email_reg" placeholder="Email">
<label for="haslo_reg">Password</label>
<input type="password" name="password" id="pass_reg" placeholder="Password">
<button type="submit">Register</button>  
</form>

to:

<form>
<label class="error" id="reg_error"></label>
<label for="login_reg">Login</label>
<input type="text" name="login" id="login_reg" placeholder="Login">
<label for="email_reg">Email</label>
<input type="text" name="email" id="email_reg" placeholder="Email">
<label for="haslo_reg">Password</label>
<input type="password" name="password" id="pass_reg" placeholder="Password">
<input type="button" onclick="check_reg()">Register</button>  
</form>

That way, your HTML file will call your check_reg() which then calls your php-file. You don't need method=post and so on in HTML-file. All this information is already in your function.

Btw, your data-attribute in check_reg() function, I recommend that you change that to serializeArray() instead.

One more thing I just realized:

success: function(result) {

The result-variable contains the error-messages form the serverside (php). so all you have to do is:

success: function(result) {
             alert(result);

Here you are using POST request, but sending data as querystring as used for GET request.

Use data in form of object:

 data: {'login': $('#login_reg').val() ,'password':$('#pass_reg').val() ,'email':$('#email_reg').val()}

You can also check with print_r($_POST) in your php file, so that you can see, whether data is posted or not.

So use follwing code in ajax:

function check_reg() {
    $.ajax({
        url: 'reg_script.php',
        type: "POST",
        data: {'login': $('#login_reg').val() ,'password':$('#pass_reg').val() ,'email':$('#email_reg').val()},
        success: function(result) {
            if (result == 'ok') {
                alert('ok');
            }
            else if (result == 'error') {
                alert('error');
            }
            else if (result == 'empty') {
                alert('empty');
            }
        },
    });
}