AJAX+form+JQUERY动态提交数据
发布时间:2020-12-15 21:48:02 所属栏目:百科 来源:网络整理
导读:通过ajax把form表单里的数据提交到服务器非常简单,把form序列化下就可以了。 jquery中与平时唯一的不同就是把data这样serialize() scripttype="text/javascript"functiontest(){$.post("%=basePath%/HelloWorld.action",$("#form1").serialize(),function(d
通过ajax把form表单里的数据提交到服务器非常简单,把form序列化下就可以了。 jquery中与平时唯一的不同就是把data这样serialize() <scripttype="text/javascript"> functiontest(){ $.post("<%=basePath%>/HelloWorld.action",$("#form1").serialize(),function(data,status){ alert("数据:"+data+"n状态:"+status); }); } </script> <formid="form1"method="post"> Firstname:<inputtype="text"name="firstName"value="Bill"/><br/> user.username<inputtype="text"name="user.username"value="userName"/><br/> user.name.showName<inputtype="text"name="user.name.showName"value="nameShow"/><br/> </form> <inputtype="button"name="b"value="测试Ajax"onclick=test()> publicvoidajax()throwsIOException{ PrintWriterout=ServletActionContext.getResponse().getWriter(); out.println("OK"); System.out.println(user.getUsername()); System.out.println(user.getName().getShowName()); System.out.println("................"); } 对,你没有看错,我用的struts框架做的测试。。form表单中要提交的数据必须有name属性,可以说跟平时的一样。 试试serialize() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |