unterminated string literal 解决方法

最近很长一段时间都在想办法处理Ajax跨域的问题,远程的数据取到了,可就是老是解析不了,一解析就报unterminated string literal 的错误,而我却还以为没有跨域问题没解决好,一直沿着jquery jsonp的路线往下走,浪费了好多时间还没解决问题,偶然间看到下面的代码,就想着试试看,结果带到servlet中一试,问题就解决了,唉真是。。。。。尼玛,真心想讲句脏话!!!!!!!!!!!!


//resultString = resultString.replace("\n\r", "<br>&nbsp;&nbsp;");//这句会报错,去掉
resultString = resultString.replace("\r\n", "<br>&nbsp;&nbsp;");//这才是正确的!
resultString= resultString.replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
resultString =resultString.replace(" ", "&nbsp;");            
//resultString=resultString.replace("\"", "\\"+"\"");//如果原文含有双引号,这一句最关键!!!!!!

 

再补充一些:

resultString =resultString.replace("<", "&lt;");
resultString =resultString.replace(">", "&gt;");
resultString =resultString.replace("&", "&amp;");
resultString=resultString.replace("\n\n","");
resultString = resultString.replace("\"","\\\\\"");
resultString = resultString.replace("\n", "");

你可能感兴趣的:(Ajax,json,jsp)