jquery js ajax 不错的想法
2015-09-17 17:55
645 查看
<scriptlanguage="JavaScript"> $(document).ready(function(){ $('#YOUR_FORM').submit(function(){// catch the form's submit event $.ajax({// create an AJAX call... data: $(this).serialize(),// get the form data type: $(this).attr('method'),// GET or POST url: $(this).attr('action'),// the file to call success:function(response){// on success.. $('#DIV_CONTAINING_FORM).html(response);// update the DIV}});returnfalse;});});</script>
EDIT
As pointed out in the comments sometimes the above won't work. So try the following:
<scripttype="text/javascript">var frm = $('#FORM-ID'); frm.submit(function(){ $.ajax({ type: frm.attr('method'), url: frm.attr('action'), data: frm.serialize(), success:function(data){ $("#SOME-DIV").html(data);}, error:function(data){ $("#MESSAGE-DIV").html("Something went wrong!");}});returnfalse;});</script>
相关文章推荐
- JQuery直接调用asp.net后台WebMethod方法
- JQuery直接调用asp.net后台WebMethod方法
- Java: Strut2 + MySql + Hibernate + ajax(jQuery)中文乱码解决办法
- jquery扩展插件开发方法
- jquery实现字数限制,超过部分...代替,后缀点击展开,点击后展开全文
- jquery回车提交表单
- Jquery中$.load(),$.get(),$.post(),$.ajax(),$.getJSON()的作用与不同
- jquery 滚动条在最下面
- jquery复选框 选中事件 及其判断是否被选中_常用笔记
- jquery的blur之后,focus获取不到焦点。
- jquery-2.1.4中toggle无法生效
- Jquery页面中添加键盘按键事件,如ESC事件
- JQuery实现滑动开关效果
- Jquery实现内容切换选项卡
- Django+Json+Jquery产生局部刷新
- [JS]jQuery,javascript获得网页的高度和宽度 【转】
- jquery实现简单的Tab切换菜单
- 利用jquery实现导航栏
- jQuery实现可用于博客的动态滑动菜单完整实例
- 【CODE】DOM、Jquery、D3.js字体放大缩小效果