国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

ajax 請(qǐng)求如何解決亂碼

2019-11-17 01:28:12
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
Ajax 請(qǐng)求如何解決亂碼

今天遇到一個(gè)問(wèn)題,有關(guān)ajax 請(qǐng)求中傳輸中文,遇到亂碼的問(wèn)題。

如下代碼:

function UpdateFolderInfoByCustId(folderId, folderName, custId) { $.ajax({ type: "Post", contentType: "application/x-www-form-urlencoded; charset=utf-8", url: "http://localhost/CRM/Ashx/HandKBSucessCustomer.ashx?Method=UpdateCustomerByCustId&folderId=" + folderId + "&folderName=" + encodeURI(encodeURI(folderName)) + "&custId=" + custId, success: function (msg) { alert(msg); }, error: function (error) { alert(error); } });}

如上代碼 如果只是傳“&foderName=”+folderName 的話,漢字就會(huì)產(chǎn)生亂碼,如果經(jīng)過(guò)encodeURL 轉(zhuǎn)換兩次的話,漢字編碼會(huì)變?yōu)轭愃?/p>

“%e6%b5%8b%eb%af%95” 的格式。轉(zhuǎn)換為這種格式之后,在獲取的時(shí)候在轉(zhuǎn)碼,如下所示:

public void UpdateCustomerByCustId() { int folderId = Convert.ToInt32(Request["folderId"]); string folderName = Request["folderName"]; string folderName2 = Convert.ToString(System.Web.HttpUtility.UrlDecode(folderName)); int custId = Convert.ToInt32(Request["custId"]); bool res = false; try { res = CustomerBusiness.UpdateCustomerByCustId(folderId, folderName2, custId); } catch (Exception ex) {throw; } Response.Write(res); } }}

經(jīng)此轉(zhuǎn)換之后,即可獲取到傳輸?shù)臐h字。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 读书| 洱源县| 温宿县| 东光县| 中宁县| 乳源| 修文县| 高陵县| 广汉市| 汉中市| 汶川县| 六安市| 高陵县| 时尚| 翁牛特旗| 镇宁| 上蔡县| 诸城市| 富平县| 家居| 南平市| 朔州市| 唐山市| 吴堡县| 陆良县| 车险| 阳东县| 乐东| 娄烦县| 新蔡县| 织金县| 南涧| 海安县| 平顺县| 小金县| 汉寿县| 镇江市| 深泽县| 北安市| 唐海县| 五家渠市|