jQuery ajaxSubmit 实现ajax提交表单局部刷新
作者:海山 发布时间:2024-05-02 17:05:35
标签:jquery,ajaxsubmit,局部刷新
AJAX简介
AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。
AJAX 不是新的编程语言,而是一种使用现有标准的新方法。
AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下。
需要引入 : jquery-form.js
使用说明:
Java代码
$(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;
});
});
调用前后方法:
Java代码
// 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.');
}
项目中可以写一个公用的方法:
Java代码
// 局部提交表单
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.主页面:
Java代码
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。
Java代码
/**
* AJAX汇总查询 未公开知情人列表
* 部门合规风控专员 汇总查询
*/
public String ajaxgatherinsiderlist() {
//相关业务数据查询
return SUCCESS;
}
以上所述是小编给大家介绍的jQuery ajaxSubmit 实现ajax提交表单局部刷新 网站的支持!
来源:http://www.cnblogs.com/yqskj/archive/2013/06/05/3119479.html


猜你喜欢
- 目录一、建立画布二、用plt.subplot函数建立坐标系,并分别绘制折线图和柱状图三、完整代码如下所示四、对应效果图如下所示一、建立画布i
- 使用MySQL,安全问题不能不注意。以下是MySQL提示的23个注意事项:1.如果客户端和服务器端的连接需要跨越并通过不可信任的网络,那么就
- 一、前言CRITIC权重法是一种比熵权法和标准离差法更好的客观赋权法:它是基于评价指标的对比强度和指标之间的冲突性来综合衡量指标的客观权重。
- 英文文档:class complex([real[, imag]])Return a complex number with the val
- 使用字符串建立查询能加快服务器的解析速度吗?我记的在那儿看过,好像是说使用字符串建立SQL查询是有它的道理的,像这样:<%mySQL=
- 需求已知年份和历年最大冻土深度,计算最大冻土深度Mk突变检验。原理工具和语言pythonjupter notebook代码过程定义函数def
- unsigned 既为非负数,用此类型可以增加数据长度! 例如如果 tinyint最大是127,那 tinyint unsigned 最大
- 上一篇中的方法在 webpack 更新后,uglify 缓存地址也发生了变化,需要重新找地址。后来测试发现不论是 uglify-js2 ug
- 本文实例讲述了Python数据结构与算法之图的广度优先与深度优先搜索算法。分享给大家供大家参考,具体如下:根据 * 的伪代码实现:广度优先
- 网上的SQL优化的文章实在是很多,说实在的,我也曾经到处找这样的文章,什么不要使用IN了,什么OR了,什么AND了,很多很多,还有很多人拿出
- 用requests包请求https的网站时,我们偶尔会遇到证书问题。也就是常见的SSLerror,遇到这种问题莫慌莫慌。这里没有找到合适的网
- 网上http接口自动化测试Python实现有很多,我也是在慕课网上学习了相关课程,并实际操作了一遍,于是进行一些总结,便于以后回顾温习,有许
- 本文只是几年前学习的tkinter的时候写的测试程序,十分之简陋,只是学习用,没什么其他用处。学习一下莫烦Python的tkinter教程,
- 本文实例为大家分享了Python3定时发送邮件功能的具体代码,供大家参考,具体内容如下1、 导入模块import osimport date
- 引言基于net包的小应用完整代码已经上传到github GitHub-TCP欢迎star和issueTCP介绍特点面向连接的运输
- 一、简介urllib.request.urlopen()函数用于实现对目标url的访问。函数原型如下:urllib.request.urlo
- 一、旧式的字符串格式化% 操作符参考以下示例:>>> name = "Eric">>>
- tkinter介绍tkinter是python自带的GUI库,是对图形库TK的封装tkinter是一个跨平台的GUI库,开发的程序可以在wi
- 在Matplotlib实际使用中会有生成不同大小subplots的需求。import numpy as np import matplotl
- 在大多数场景中,我们都用 lxml 库解析网页源码,但你是否知道,lxml 库也是可以操作 svg 图片的。我们可以使用