【发布时间】:2011-07-22 13:54:18
【问题描述】:
好吧,我有点不知所措,因为 AJAX 绝对是一个薄弱环节。我有一个页面需要通过 ajax 将注册表单发送到另一个域以进行处理,然后返回成功/失败消息。
当使用下面的代码时,页面只是刷新了,什么都没有发送?
表格代码:
<form method="post" onSubmit="return submitGetApp();" class="kinkast_signup">
<input id="login_email" type="text" name="to" />
<input id="signInButtonSubmit" type="submit" name="action" value="Send" />
</form>
jQuery 代码: $('#signInButtonSubmit').click(function (e) {
//Get the data from all the fields
var number = $('input[name=to]');
//Simple validation to make sure user entered something
//If error found, add hightlight class to the text field
if (number.val()=='') {
name.addClass('hightlight');
return false;
} else name.removeClass('hightlight');
//organize the data properly
var data = 'number=' + number.val();
//show the loading sign
$('p.ajax_message').hide();
//start the ajax
$.ajax({
//this is the php file that processes the data and send mail
url: "http://video.kinkast.com/getapp",
//GET method is used
type: "POST",
//pass the data
data: data,
//Do not cache the page
cache: false,
//success
success: function () {
$('p.ajax_message').html('Success!');
alert('Worked!');
},
//Failure
error: function(xhr, status, e) {
alert(status, e);
}
});
//cancel the submit button default behaviours
return false;
});
有人可以查看代码并查看我缺少的内容吗?另外,要现场观看,请访问this link
【问题讨论】:
标签: jquery html ajax json forms