weblogic下ajax无法进入返回函数

来源:互联网 发布:文华财经交易模型源码 编辑:程序博客网 时间:2024/06/18 13:40


开发环境Tomcat  测试环境weblogic

问题:Tomcat下ajax请求struts1的action返回中文没问题!

    $.ajax({      type:"get",    //contentType:"application/json",    cache:"false",            url:"",            dataType:"text",            data:"userName="+userName,            success:function(result){             alert(result);            }        })

action中

response.getOutputStream().print(msg);

weblogic做测试无法进入success:函数

解决:使用java.net.URLEncoder进行编码,js中使用decodeURI()进行解码;

注:ajax的type:"get"   dateType="text"

java

msg = URLEncoder.encode("用户名输入不合法!","utf-8");outMessage(out, msg);
js
$.ajax({      type:"get",    //contentType:"application/json",    cache:"false",            url:"",            dataType:"text",            data:"userName="+userName,            success:function(result){             alert(decodeURI(result));            }        })

Ps:我遇到的是英文的“逗号”会进行转码失败,中文的“逗号”转码成功!


0 0
原创粉丝点击