`
ollevere
  • 浏览: 261239 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

jQuery ajax表单提交实现局部刷新

阅读更多

jQuery ajaxSubmit可以实现AJAX提交表单 局部刷新页面DIV  (可以实现刷新JSP TABLE 哦!)

 

需要引入 : jquery-form.js

 

 

使用说明:

$(document).ready(function() { 
    var options = { 
        target:        '#mydiv',   // 需要刷新的区域
        //beforeSubmit:  showRequest,  // 提交前调用的方法
        //success:       showResponse  // 返回后笤俑的方法
 
        // other available options: 
        //url:       url         // 提交的URL, 默认使用FORM  ACTION 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // 是否清空form
        //resetForm: true        // 是否重置form
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // 绑定FORM提交事件
    $('#myForm').submit(function() { 
        $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
}); 

 

 

调用前后方法:

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 
 

 

项目中可以写一个公用的方法:

// 局部提交表单
function formSubmit(formId, divId, url) {
   $('#' + formId).submit(function() {
   $(this).ajaxSubmit( {
      target : '#' + divId,
      url : url,
      error : function() {
         alert('加载页面' + url + '时出错!')
      }
   });
   return false;
   });
}
 

 

=====================================================================

事例 刷新TABLE:

 

1.把TABLE单独放一个JSP,主页面 include TABLE页面。

 

2.主页面:

 

window.onload=function (){
            //AJAX 提交FORM刷新TABLE
            $('#queryForm').submit(function() {
                $(this).ajaxSubmit( {
                    target : '#table1'
                });
             return false;
       });
}
 

点击查询按钮  提交FORM。

 

3.JAVA:FORM提交调用的方法和 普通的ACTION写法一样, STRUTS里配置该ACTION跳转到  那个单独的TABLE JSP页面,返回成功后,就会看到刷新了TABLE。 

/**
 * AJAX汇总查询 未公开知情人列表
 * 部门合规风控专员 汇总查询
 */
public String ajaxgatherinsiderlist() {
    //相关业务数据查询
	return SUCCESS;
}
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    jQuery ajaxSubmit 实现ajax提交表单局部刷新

    主要介绍了jQuery ajaxSubmit 实现ajax提交表单局部刷新 的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下

    JQuery 又谈ajax局部刷新

    JQuery 再谈ajax局部刷新。 案例: 描述: 1. 点击登录则弹出登录对话框 2. 如果用户名密码不正确,则提示错误信息 3. 当输入信息正确,则刷新登录信息,显示用户名和退出按钮 4. 点击退出弹出提示信息...

    Jquery具体实例介绍AJAX何时用,AJAX应该在什么地方用

    在jquery中ajax实现方法分类很多种,如有:load、jQuery.get、jQuery.post、jQuery.getScript、jQuery Ajax 事件、jQuery.ajaxSetup等等,前面几种为常用的也是用得最多的jquery ajax方法了. 网站开发时,ajax是一个...

    jQuery Ajax全解析

    想要更新内容或者提交表单就要重新加载或刷新页面。 使用ajax技术的网页 通过后台服务器进行少量的数据交换,网页就可以实现异步局部跟新。 Ajax出现前 Ajax技术出现之前,是一个同步交互的世界。 同步:客户端发出...

    jQuery+Ajax+PHP弹出层异步登录效果(附源码下载)

    常见的应用有弹出登录表单层,用户提交登录信息,后台验证登录成功后,弹出层消失,主页面局部刷新用户信息。本文我们将给大家介绍如何使用jQuery+Ajax+PHP弹出层异步登录的应用。 效果展示 源码下载 HTML 由于本...

    netcoss电信计费系统

    Ajax:异步请求处理,页面局部刷新 SpringMVC:接收请求,转发处理(前段控制) SpringIOC:组件解耦(采用注入) MyBatis:数据库访问(实现DAO) 3.======资费管理====== 作用:资费主要是服务的收费标准进行维护...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    --我们做了优化,现在要使一个Asp.net的按钮能够AJAX提交,你不需要做任何设置(PageManager的属性EnableAjax为true即可,这是默认属性)。 +PageManager的实例方法AddAjaxUpdateControl改名为...

    ExtAspNet_v2.3.2_dll

    -使得Asp.net的控件ImageButton具有和Asp.net的Button控件类似的行为(Ajax提交)(feedback:261629698)。 +TabStrip增加GetAddTabReference和GetRemoveTabReference两个函数,用来向TabStrip控件动态增加删除Tab。...

    千方百计笔试题大全

    167、Prototype如何实现页面局部定时刷新? 40 168、Prototype如何为一个Ajax添加一个参数? 40 169、Ajax请求总共有多少种Callback? 41 170、Javascript如何发送一个Ajax请求? 41 171、AJAX都有哪些有点和缺点? ...

    java面试宝典

    167、Prototype如何实现页面局部定时刷新? 40 168、Prototype如何为一个Ajax添加一个参数? 40 169、Ajax请求总共有多少种Callback? 41 170、Javascript如何发送一个Ajax请求? 41 171、AJAX都有哪些有点和缺点? ...

    《JavaScript实例精通》[源代码]

    16_1.htm 无刷新实现图片切换。 16_2.htm 很酷的导航特效。 16_3.htm 加载一个文本文件到一个HTML元素中。 16_4.htm 使用XML HTTP载入一个XML文件。 16_5.htm 通过XML HTTP做一个HEAD的请求。 16_6.htm ...

    JavaScript实例精通

    16_1.htm 无刷新实现图片切换。 16_2.htm 很酷的导航特效。 16_3.htm 加载一个文本文件到一个HTML元素中。 16_4.htm 使用XML HTTP载入一个XML文件。 16_5.htm 通过XML HTTP做一个HEAD的请求。 16_6.htm ...

Global site tag (gtag.js) - Google Analytics