当我提交我的表格时,我想在成功的时候获得成功。我用的是jquery
$('#new_invitation').submit(function(e) {
var $this = $(this);
$this.on('ajax:success', function(e) {
alert ('Success');
});
});
成功的警报不会被触发:(.
为什么?
发布于 2012-03-06 11:12:16
你好吗?在我看来,您实际上并没有使用AJAX提交表单,因为submit()函数将触发表单的正常提交。你能试试这个密码吗?
$('#new_invitation').live('submit', function(event){
event.preventDefault(); //Stops the normal form submission process
form = $(this);
data = form.serialize(); //serializes the form data
jQuery.ajax({
type: 'POST',
dataType: 'JSON', // JSON, HTML, whatever your API responds to
url: form.attr('action'), //fetches the URL from the form
success: function(data,textStatus,jqXHR){
//Success callback
alert('success');
}
});
});
这假设'#new_invitation‘是表单标记的ID。我建议您查看一下jQuery文档站点,它们有大量关于AJAX:http://api.jquery.com/jQuery.post/的信息。
祝好运!
https://stackoverflow.com/questions/9582273
复制相似问题