Jquery unescape response text from java servlet not working properly -
java code
presponse.setheader("content-type", "text/plain;chartset=utf-8"); presponse.setcontentlength(resultsjson.length()); writer out = presponse.getwriter(); string escapedjsonstring = stringescapeutils.escapejavascript(resultsjson); out.write(escapedjsonstring);
the purpose escape return text because there accented character in 'resultsjson' , though set charset=utf-8, still garbled text ajax. check question me ajax garbled text
ajax code
var option = { type : 'post', url : $('#csrorderexportform').attr('action'), data : $('#csrorderexportform').serialize(), beforesend : preajaxreqest, datatype:'text', error : function(data, statustext, error){ $(".searchsubmitbtn").removeattr("disabled"); seterrormessage('no records found!'); }, success : function(data){ if (data) { alert(unescape(data));} } }; $.ajax(option);
response text
[{\"ordernumber\":\"s301020000\",\"customerfirstname\":\"\u5f20\u79d1\",\"customerlastname\":\"\u5f20\u79d1\",\"orderstatus\":\"pending_fulfillment_request\",\"ordersubmitteddate\":\"may 13, 2015 1:41:28 pm\"}]
after unescape text jquery, getting same text.
expected output
[{"ordernumber":"s301020000","customerfirstname":"张科","customerlastname":"张科","orderstatus":"pending_fulfillment_request","ordersubmitteddate":"may 13, 2015 1:41:28 pm"}]
this should work:-
presponse.setcontenttype("application/json"); presponse.setcontentlength(resultsjson.length()); writer out = presponse.getwriter(); string escapedjsonstring = stringescapeutils.escapejavascript(resultsjson); out.println(escapedjsonstring);
Comments
Post a Comment