DIV CSS 佈局教程網

jQuery ajax 中文亂碼
編輯:JQuery常見問題     

使用 jQuery ajax 傳送中文時,若後端取到亂碼,通常與編碼設定有關。可依情境選擇前端編碼或指定 contentType。

方法一:前端編碼

data: { id: 1, type: encodeURI(encodeURI('商品')) }

後端再以 URLDecoder.decode(type, "UTF-8") 還原。

方法二:指定 contentType

contentType: "application/x-www-form-urlencoded; charset=UTF-8"

關鍵在於明確宣告 UTF-8,避免 jQuery 預設未帶 charset 時造成解讀差異。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved