Ajax 交付整个表单

Ajax 提交整个表单

serialize方法 实现提交表单

 

javascript

 $.ajax({
			type : "POST",
			url : "testAction.action?time="+Math.random(),
			data : $('#formMain').serialize(),
			success : function(data) {

			},
			error : function(xhr) {
				fnGotoErrorPage();
			}
		});

 

jQuery

 $.post("testAction.action?time="+Math.random(),$('#formMain').serialize(),function(xml){
        	
        });

 

 

 

下面转载内容

 

jQuery ajax - serialize() 方法
定义和用法

serialize() 方法通过序列化表单值,创建 URL 编码文本字符串。

您可以选择一个或多个表单元素(比如 input 及/或 文本框),或者 form 元素本身。

序列化的值可在生成 AJAX 请求时用于 URL 查询字符串中。

JavaScript code
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<form>
  <div><input type="text" name="a" value="1" id="a" /></div>
  <div><input type="text" name="b" value="2" id="b" /></div>
  <div><input type="hidden" name="c" value="3" id="c" /></div>
  <div>
    <textarea name="d" rows="8" cols="40">4</textarea>
  </div>
  <div><select name="e">
    <option value="5" selected="selected">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
  </select></div>
  <div>
    <input type="checkbox" name="f" value="8" id="f" />
  </div>
  <div>
    <input type="submit" name="g" value="Submit" id="g" />
  </div>
</form>
 
$('form').submit(function() {
  alert($(this).serialize());
  return false;
});


输出 a=1&b=2&c=3&d=4&e=5 后台request.getParameter("a")就能获取到value