我是jQuery的新手。我正在尝试创建一个meme网站,当我想使用boostrap的模态对话框创建登录/注册页面时,我陷入困境。当有人按下“创建帐户”将所有数据从输入传递到AJAX时,我想让它工作,然后将它们插入到数据库中。
这是我的代码
<div id="deleteMessage" class="modal fade in" style="display: none; ">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><center>Sign Up!</center></h4>
</div>
<div class="modal-body">
<?
$errorid = $_GET['errorid'];
if($errorid == 1)
echo "<div class='alert alert-danger'>Scuze, dar acest nume de utilizator este deja folosit!</div>";
else if($errorid == 2)
echo "<div class='alert alert-danger'>Parolele nu coincid, te rugam sa le rescrii cu mai multa atentie!</div>";
else if($errorid == 3)
echo "<div class='alert alert-danger'>E-Mailul scris este deja folosit de catre un alt utilizator!</div>";
else if($errorid == 4)
echo "<div class='alert alert-danger'>Trebuie sa accepti termenii si conditiile pentru a te putea inregistra!</div>";
?>
<br>
<form action="register.php" method='POST'>
<fieldset>
<input type='text' name='username' class='form-control' placeholder='Username'>
<br>
<input type='password' name='password' class='form-control' placeholder='Parola contului...'>
<br>
<input type='password' name='password2' class='form-control' placeholder='Confirma parola'>
<br>
<input type='email' name='email' class='form-control' placeholder='E-Mail'>
<br>
<input type = 'radio' name='terms' value='1'> Accept <a href='" . $rewUrl->rewriteUrl(false, "terms") . "'>termenii si conditiile</a>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal"><span class='glyphicon glyphicon-remove'></span> Inchide</button>
<button class="btn btn-warning" id="newDatssa"><span class='glyphicon glyphicon-ok'></span> Creaza Contul</button>
</div>
</div>
</div>
</div>
显示模态对话框的按钮:
<a data-toggle="modal" href="#deleteMessage">Sign Up</a>
最后是jQuery代码:
$(function()
{
$("button#newData").click(function()
{
$.ajax({
type: "POST",
url: "register.php",
data: $('form.contact').serialize(),
success: function(msg)
{
$("#deleteMessage").modal('hide');
},
error: function()
{
alert("failure");
}
});
});
});
我曾经尝试过什么,我总是从警报中得到“失败”的消息,我不知道该怎么做,将值传递给ajax,任何想法?
感谢。