惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
T
Threat Research - Cisco Blogs
N
News and Events Feed by Topic
Hacker News: Ask HN
Hacker News: Ask HN
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
Security Latest
Security Latest
Spread Privacy
Spread Privacy
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
U
Unit 42
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Scott Helme
Scott Helme
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
爱范儿
爱范儿
S
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Latest news
Latest news
GbyAI
GbyAI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
PCI Perspectives
PCI Perspectives
Jina AI
Jina AI
AI
AI
NISL@THU
NISL@THU
I
Intezer
G
GRAHAM CLULEY
B
Blog
S
Secure Thoughts
IT之家
IT之家
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
V2EX - 技术
V2EX - 技术
Recorded Future
Recorded Future
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - 叶子绿了

freemarker显示含有html代码的内容 .net sql 防注入 httpmodule [转载]poi导出excel,可以自定义保存路径 Struts2下多文件的上传与下载 dwr框架 Oracle 9i中包含Connect by 子句的查询向Oracle 10g移植后运行时错误及解决方法 JQuery Uploadify 基于JSP的无刷新上传实例 写了个用jquery控制select只读(select选项可以供用户查看但不能改变初始选中值) C#之模态窗口关闭 repeater相同行合并 在Web站点中创建和使用Rss源(动态) silverlight xml查询 silverlight 3 数据绑定及分页 解决ASP.NET中Image控件不能自动刷新 解决UpdatePanel无法直接弹出窗口的问题 导入Excel数值读不到,找不到可安装的 ISAM错误! asp.net2.0 上传大容量文件第三方控件radupload 浏览器不能正常解析CSS代码的解决 ajax在用户注册中的应用,类似淘宝网
jquery ajax 传递js对象到后台
叶子绿了 · 2013-09-03 · via 博客园 - 叶子绿了

第一种:通过struts接收

(function ($) {
        $("#btnsave").click(function () {            
            var params = {};            
                params["gaglid.dwfd"] = $("#dwfd").val();                 
                params["gagl.gamc"] = $("#gamc").val();    
<%--                console.log($.param(params,true));--%>
<%--                console.log(decodeURIComponent($.param(params)));--%>
<%--                console.log(encodeURI(encodeURI(decodeURIComponent($.param(params)))));--%>			
				console.log($.param(params,true));
            var jqxhr = $.ajax({
                url: "save1Gagl.action?_=" + new Date().getTime(),
                type: "post",               
                contentType: "application/x-www-form-urlencoded; charset=utf-8",
                data: encodeURI($.param(params,true)),     //ajax传数组参数给struts2自动接收
                dataType: "text"
            });
            jqxhr.done(function (data) {            	
                alert(data);
            });
        });
    })($);

后台定义gaglid和gagl

public void save1()
	{
		try {
		if(null==gaglid||null==gaglid.getBh()||this.gaglid.getBh().equals(""))
		{
			this.gaglid.setBh(this.getbhmethod());
		}
		gagl.setId(gaglid);
		gagl.setGamc(URLDecoder.decode(gagl.getGamc(), "utf-8"));
	
		
//		gagl_Ithc_Server.saveOrUpdate(gagl);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/x-www-form-urlencoded; charset=utf-8");
		PrintWriter out;
			out = response.getWriter();
			out.write("success");
			out.flush();
			out.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

第二种:手动接收

//把要保存的个案,流调,送检单,传染病整合成一个js对象
			var gamerge={};
			gamerge.gagl=gamodel;
			gamerge.lxbdc=lxbdcmodel;
			gamerge.listsjdj=objs;
			gamerge.listcrbbg=crbbgobjs;			
			var jqxhrga = $.ajax({
	        	url: "save2AjaxGamerge.action?_=" + new Date().getTime(),
	            type: "post",
	            contentType: "application/json;charset=utf-8",
	            data:escape(encodeURIComponent(JSON.stringify(gamerge))), //把js对象转换成json  JSON.stringify(objs)
	            dataType: "text"
	        });
	  		jqxhrga.done(function (data) {	  			
	  			alert(data);
	  			window.opener.location.href=window.opener.location.href;   
	  			window.close();	  
	  			
	        });
	  		jqxhrga.fail(function(e){
	        	alert('保存个案出错'+e);
	        });

 后台手动接收

HttpServletRequest req=ServletActionContext.getRequest();
		try {
			req.setCharacterEncoding("utf-8");
			String t=readJSONStringFromRequestBody(req);
			t=java.net.URLDecoder.decode(java.net.URLDecoder.decode(t,"utf-8"),"utf-8");			

			//处理时间
			GsonBuilder gsonBuilder = new GsonBuilder();
		    gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
		        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		        public Date deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context)
		                throws JsonParseException {
		            try {
		                return df.parse(json.getAsString());
		            } catch (ParseException e) {
		                return null;
		            }
		        }
		    });	
 Gson gson = gsonBuilder.create();
		    GaLdSjCrb galdsjcrb=gson.fromJson(t, new TypeToken<GaLdSjCrb>() {  
                }.getType());
String tsxx="保存成功!";

HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/x-www-form-urlencoded; charset=GBK");
PrintWriter out = response.getWriter();
out.write(tsxx);
out.flush();
out.close();