我使用dojo和struts 1.3.8,我想通過dojo.xhrGet將一些「特殊」字符(如è,°,ù,€)傳遞給動作struts saveBill。但是,當我打印JSON的動作它給了我DOJO xhr使用特殊字符獲取json
è la prova n°10
我不知道問題出在哪裏,我將所有內容類型爲UTF-8在所有的JSP ...我也用過struts過濾器編碼在UTF-8 ...沒有...我錯了哪裏? 這是JavaScript代碼
var billJson = {"row":"0","descr":"è la prova n°10"};
dojo.xhrGet({
url: "saveBill.do",
headers: {'bill': billJson, 'Content-Type': 'application/json; charset=UTF-8'},
handleAs: "text",
load: function(response, ioArgs) {
showMessage(response);
},
error: function(message, ioArgs) {
showMessage(message);
}
});
,這是響應標頭(來自螢火蟲複製&糊)
Host localhost:9080
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0
Accept text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8
Accept-Language it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip, deflate
Accept-Charset UTF-8,*
Keep-Alive 115
Connection keep-alive
bill {"row":"0","descr":"è la prova n°10"}
Content-Type application/json; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://localhost:9080/CA3_S_001/login.do
Cookie invoiceTreeSaveStateCookie=undefined%2C000001%2C000014; JSESSIONID=0000QeyArD4K7CDr_oyNkrpw9Zk:-1
謝謝!
您正在將數據傳遞到名爲「bill」的標題字段中?你爲什麼在傳遞JSON時使用handleAs = text? 「文本」不會做任何轉義,所以你必須編碼你的非ASCII字符。 – 2011-04-06 05:19:33
你的服務器在內容上聲明utf-8,但是你確定服務器上的內容實際上是在utf-8中編碼(匹配)的嗎? – peller 2011-04-08 02:35:28