ITeye博客

又见 Jquery Ajax Post乱码

msnvip · 2009-10-13 15:16 · js-ajax · Markdown

var contents = encodeURIComponent(document.getElementById("content-"+id).value);
	//var contents = document.getElementById("content-"+id).value;
	var castellanId = document.getElementById("castellan-"+id).value;

	alert(contents);
	
	if (handleType == 'read') {
		$.post('handleSuggestDomainAction.action', {
		    sbt: 'sbrd',
		    content: contents,
		    cid: castellanId,
		    sgId: id
		}, function() {
		    //alert('哈哈.回复/处理成功!');
		    window.location.href =window.location.href;
          	window.location.href.reload();
		    //window.location.reload();
		});				
	}

 

 

 环境: Jquery1.3.2 ,Struts2

 

页面:

jsp中,改成红色显示的那样

 

var contents = encodeURIComponent(document.getElementById("content-"+id).value);

服务器端:

contentCn = URLDecoder.decode(content, "UTF-8");

 

乱码解决..

以前记得要页面上 encode 2次的.貌似记错了?

评论(2)

  1. #2 楼 · theoffspring · 2011-08-29 11:45

    好用,如果前台用escape,后台解不了码,只能用这种办法了。

  2. #1 楼 · songfantasy · 2009-11-11 13:49

    js中要进行两次encode才可以。没错。

评论功能维护中,当前仅展示历史评论。