---
title: "表单异步提交的方法"
author: "mywebcode"
date: "2013-11-29T19:10:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2014-04-30T09:16:43Z"
id: 2058353
url: "https://mywebcode.iteye.com/blog/2058353"
---

将遇到的表单异步提交的方式记录一下：

表单异步提交注意点：  
a.表单中的name一定要跟java中接收参数的名称一样。  
b.表单中提交的参数的个数要跟，java中接收参数的个数一样多。不能多也不能少，否则提交不到。

$.post('addshipaddress.html', $('form#addressForm').serialize(), function(data){  
alert(data);  
}, 'text');  
（1）：url //addshipaddress.html 表单提交到哪里

（2）：data参数 这里是表单的参数传递 $('form#addressForm').serialize() 注意不能用单引号

如'$('form#addressForm').serialize()' 则会报错

（3）：function(data)回调函数 还有一种写法 看如下写法。。另写给个function函数

$.post('addshipaddress.html', $('form#addressForm').serialize(), function(data){  
confirmSuccess(data);  
}, 'text');

}

function confirmSuccess(data) {  
alert(data);  
window.location.reload();  
}

（4）：text 为你想要返回得到的内容的形式， 可以是xml , json ,text 等格式

还有其他提交方式 。。。。。待续。。。。。