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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -