วันนี้ฉันพบปัญหาเกี่ยวกับการส่งภาษาจีนในคำขอ AJAX และพบรหัสที่อ่านไม่ออก
รหัสต่อไปนี้:
การคัดลอกรหัสมีดังนี้:
ฟังก์ชั่น updateFolderInFobyCustId (folderId, folderName, custid) {
$ .ajax ({
ประเภท: "โพสต์",
ContentType: "แอปพลิเคชัน/x-www-form-urlencoded; charset = utf-8"
URL: "http: //localhost/crm/ashx/handkbsucesscustomer.ashx? method = updateCustomerByCustid & folderId ="
+ folderId + "& folderName =" + encodeuri (encodeuri (folderName)) + "& custid =" + custid,
ความสำเร็จ: ฟังก์ชั่น (ผงชูรส) {
การแจ้งเตือน (ผงชูรส);
-
ข้อผิดพลาด: ฟังก์ชั่น (ข้อผิดพลาด) {
การแจ้งเตือน (ข้อผิดพลาด);
-
-
-
หากรหัสข้างต้นเพิ่งผ่าน "& fodername ="+folderName อักขระภาษาจีนจะสร้างรหัสที่อ่านไม่ออก
"%E6%B5%8B%EB%AF%95" หลังจากแปลงเป็นรูปแบบนี้จะถูกแปลงรหัสเมื่อได้รับดังที่แสดงด้านล่าง:
การคัดลอกรหัสมีดังนี้:
โมฆะสาธารณะ updateCustomerByCustid ()
-
int folderId = Convert.toint32 (คำขอ ["folderId"]);
string folderName = คำขอ ["folderName"];
สตริง folderName2 = Convert.toString (System.web.httputility.urldecode (folderName));
int custid = Convert.toint32 (คำขอ ["custid"]);
บูล res = false;
พยายาม
-
res = customerbusiness.updatecustomerbycustid (folderid, folderName2, custid);
-
จับ (Exception Ex)
-
โยน;
-
Response.write (res);
-
-
-
หลังจากการแปลงนี้สามารถรับอักขระจีนที่ส่งผ่านได้