The garbled of Get and post when JS calls Ajax

Source: Internet
Author: User
Tags chr

  When using "get", the crawled page is finally encoded with the encoding type  

  Code as follows: <%  server-side: Servletactioncontext.getresponse (). setcharacterencoding ("Utf-8");  client page effects p/ jsp.html target=_blank >jsp Tutorial: <%@ page language= "java" contenttype= "text/html"; Charset=utf-8 "pageencoding=" utf-8 "%>  response.expires = -9999  Response.AddHeader" Pragma "," No-cache "   Response.AddHeader "Cache-ctrol", "No-cache"   Response.AddHeader "Content-type", "text/html"; charset=gb2312 "' This is the key, otherwise there will be garbled   Response.Write" Chinese characters "%>    2, in the use of the post with VBScript to solve the coding problem:  source code is as follows:     Code as follows: <script language= "VBScript" >  function urlencoding (vstrin)   Strreturn = ""   for i = 1 to Len (vstrin)   THISCHR = Mid (vstrin,i,1)   If ABS (ASC (THISCHR)) < &hff then  Strreturn = Strre Turn & thischr  else  innercode = ASC (THISCHR)   if Innercode < 0 then  Innercode = innercode + &h10000  End if  Hight8 = (Innercode and &hff00) &hff  low8 = Innercode and &Amp;hff  Strreturn = strreturn & "%" & Hex (HIGHT8) & "%" & Hex (LOW8)   end if  next  URL encoding = strreturn  End function  function Bytes2bstr (vin)   Strreturn = ""   For i = 1 to LenB (VIN) &N Bsp Thischarcode = ASCB (MidB (vin,i,1))   If Thischarcode < &h80 then  Strreturn = strreturn & Chr (Thischar Code)   else  Nextcharcode = ASCB (MidB (vin,i+1,1))   Strreturn = Strreturn & Chr (CLng (thischarcode) * &A mp;h100 + CInt (nextcharcode))   i = i + 1  end if  next  bytes2bstr = strreturn  End function&nbsp ; </script>    Below is the use of VBScript functions:    code as follows: <script language= Web Effects > /**  * Initializes a XMLHTTP object   */  function Initajax ()   {  var ajax=false;  try {  ajax = new ActiveXObject ("Msxml2.xmlhttp"); } catch (e) {  try {  ajax = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (E) {  ajax = false; } }  if (!ajax && typeof xmlhttprequest!= ' undefined ') {  ajax = new XMLHttpRequest (); }&nbsp ; Return ajax; }  function saveuserinfo ()   {  var msg = document.getElementById ("msg");  var f = d ocument.user_info;  var username = f.user_name.value;  var userage = f.user_age.value;  var usersex = F.use r_sex.value;  var url = "save.asp tutorial";  var poststr = urlencoding ("user_name=" + username + "&user_age=" + user Age + "&user_sex=" + usersex)//post with Encoding pass   var ajax = Initajax ();  Ajax.open ("post", URL, True);  Ajax.setrequestheader ("Content-type", "application/x-www-form-urlencoded");  ajax.send (POSTSTR);  Ajax.onreadystatechange = function () {  if (ajax.readystate = 4 && ajax.status = =) {  msg.innerhtml = Bytes2bstr (ajax.responsebody); Get time decoding  } } }  </script>  <form name= "User_info" >  Name: <textarea name= " User_name "/></TEXTAREA><BR/>  Age: <input type= "text" name= "user_age"/><br/>  Sex: <input Type= "text" name= "User_sex"/><br/>  <input type= "button" value= "Submit Form" onclick= "Saveuserinfo ()" >   </form>  <div id= "MSG" ></div>  success      
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.