如何在jQuery异步中提交表单?
在mootools中我会做类似$('form_id').send({success:function(res){....}});
东西$('form_id').send({success:function(res){....}});
jQuery中的并行语法是什么?
换句话说:
如何将表单数据(假设id =’bob’)放入以下代码中
$.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType });
这应该这样做:
$.ajax({ type: 'POST', url: url, data: $('#bob').serialize(), success: success, dataType: dataType });
你不知道……它就在文档中! :P
http://api.jquery.com/jQuery.ajax/
编辑:没关系……
$('#too_cool_form').submit(function(e){ e.preventDefault(); //do some verification $.ajax({ url: '', data: $(this).serialize(), success: function(data) { //callback methods go right here } }); });
jQuery附带的任何内容都不会为您自动AJAX化一个普通的表单。
选项1 – 截取表单的submit
事件,使用serialize
从表单字段中删除数据,并按照建议使用ajax
或post
发送。
选项2 – 使用这个伟大的表单插件 ,它为您完成所有选项1。
$.post()
或$.ajax()
$.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType });
文档将最好地解释: http : //api.jquery.com/jQuery.post/