我要插入一个电子邮件地址到我的分贝与Ajax调用。 这里谈到的问题,而是工作到背景,它刷新页面。
alert("yea");
在成功的功能没有被达到
可能是什么问题
$(document).ready(function() {
$("#header-subscribe").click(function(){
var str = $("#email").val();
if(validateEmail(str)) {
$.ajax({
url: 'php/signupForm.php',
type: 'GET',
data: 'email='+str,
success: function(data) {
//called when successful
alert("yea");
},
error: function(e) {
//called when there is an error
//console.log(e.message);
}
});
形式:?
<form id="hero-subscribe" class="the-subscribe-form" >
<div class="input-group">
<input type="email" class="form-control" placeholder="Enter Your Email" id="email">
<span class="input-group-btn">
<button class="btn btn-subscribe" id="header-subscribe" type="submit">subscribe</button>
</span>
</div>
</form>
你不能阻止点击的默认操作。 –