日期:2014-05-16  浏览次数:20381 次

关于encodeURI
$.ajax({
type : "post",
url : "AddNews?title=" + encodeURI(encodeURI(title))
+ "&padCon=" + encodeURI(encodeURI(padCon))
+ "&context=" + encodeURI(encodeURI(context)),
success : function(msg) {
if ("success" == msg) {
alert("新闻发布成功!");
location.href = "News";
} else {
alert(msg);
}
}


alert的时候显示 context 是全部都有。 

但是AddNes?title=11&padCon=22&context=...

context后面值只有一半  例如:http://localhost:8080/4S/Edit?id=49&title=12312&context=%253Cspan%2520style=%2522background-color:

background-color:  后面的值没了,后面的值应该是  #111111

java后台接受到的数据:<span style="background-color:
------解决方案--------------------
# 在 url 中表示锚点,是供浏览器用的,不会被服务端接收
------解决方案--------------------
本帖最后由 showbo 于 2014-03-27 17:19:56 编辑
你加到url后面就是get提交了,get有大小限制,要放到data配置去,放到data就不用手动调用encodeURI了,jquery会自动调用encodeURIComponent帮你编码
encodeURI有部分字符不编码(; / ? : @ & = + $ , #这些)的,包括#,要用encodeURIComponent来编码
    $.ajax({
        type: "post",
        data: { title: title, padCon: padCon, context: context },////////
        url: "AddNews",
        success: function (msg) {
            if ("success" == msg) {
                alert("新闻发布成功!");
                location.href = "News";
            } else {
                alert(msg);
            }
        } 
    });