今天做项目,用jquery的ajax做了一把提交,
$.post("./xxx.do",{"userName":$("#userName").val()},function(msg){alert(msg)} );
Action里面设值
request.getWriter().write("_false");
request.getWriter().flush();
发现在IE、chrome下返回值皆正常,msg的值为_false
唯独在firefox下面返回值为一个xmlDocument对象,百思不得其解
然后对着API文档换回
$.ajax(url:"./xxx.do", data:{"userName":$("#userName").val()}, success:function(msg){alert(msg);},dataType:"html"),发现一切正常,恍然大悟,原来是post的时候没加dataType,加上之后
$.post("./xxx.do",{"userName":$("#userName").val()},function(msg){alert(msg)},"text" );或
$.post("./xxx.do",{"userName":$("#userName").val()},function(msg){alert(msg)},"html" );
果然一切正常
至于为什么不加dataType的时候IE和Chrome能正常解析,而firefox解析为xmlDocument,估计是各浏览器的默认设值不一样吧,不做深究