仅将AJAX复制到网址行

Im trying to make a login system. PHP cant be used to send data to the server since i need to run it in phone applications. It seems like all AJAX does is change the URL of my browser window when testing it, and nothing gets send to the server. Code below. The regformhash() only hashes the password. Nothing else. HTML:

<form action="#" id="registration_form">
        Username: <input type='text' name='username' id='username' /><br>
        Email: <input type="text" name="email" id="email" /><br>
        Password: <input type="password" name="password" id="password"/><br>
        Confirm password: <input type="password" name="confirmpwd" id="confirmpwd" /><br>
        <input type="button" value="Register" 
onclick="return regformhash(this.form,
                               this.form.username,
                               this.form.email,
                               this.form.password,
                               this.form.confirmpwd);" /> 
    </form>
    <p id="answer">Test</p>

Script:

$('#registration_form').submit(function( event ) {
        event.preventDefault();
        var formData = $("#registration_form").serializeArray();
        $.ajax({
            url : 'register.php',
            type : "POST",
            data : formData,
            success: function(data) {
                alert("Yes" +data);// alert the data from the server
            },
            error: function() {
                alert("No" + data);
            }
        });
    });

PHP:

$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['p'];
$skips = 5;

echo "succes";
查看全部
weixin_33729196
weixin_33729196
2014/08/14 07:53
  • php
  • html
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

3个回复