AJAX+form+JQUERY动态提交数据

通过ajax把form表单里的数据提交到服务器非常简单,把form序列化下就可以了。

jquery中与平时唯一的不同就是把data这样serialize()

<script type="text/javascript">
     function test(){
     	$.post("<%=basePath%>/HelloWorld.action",$("#form1").serialize(),function(data,status){
		alert("数据:" + data + "\n状态:" + status);
	 });
      }
</script>

<form id="form1" method="post">
        First name: <input type="text" name="firstName" value="Bill" /><br />
  	user.username <input type="text" name="user.username" value="userName"/><br />
  	user.name.showName <input type="text" name="user.name.showName" value="nameShow"/><br/>
 </form>
 <input type="button" name="b" value="测试Ajax" onclick=test()>

public void ajax() throws IOException{
	PrintWriter out= ServletActionContext.getResponse().getWriter();
	out.println("OK");
	System.out.println(user.getUsername());
	System.out.println(user.getName().getShowName());
	System.out.println("................");
}

对,你没有看错,我用的struts框架做的测试。。form表单中要提交的数据必须有name属性,可以说跟平时的一样。

试试serialize()

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...