JS get url parameter, and Chinese garbled problem

Source: Internet
Author: User

// two methods of acquisitionfunctiongetquerystring (parameter) {varReg =NewRegExp ("(^|&)" + parameter + "= ([^&]*) (&|$)"); varr = Window.location.search.substr (1). Match (REG); if(r! =NULL) {        if(parameter = = "Deid") {            $("#deId"). Val (r[2]); }        if(parameter = = "Dename") {            $("#deName"). Val (decodeURI (r[2));//solve Chinese garbled characters        }    }}functiongetrequest () {varurl = location.search;//gets the URL in the "?" String after the character        varTherequest =NewObject (); if(Url.indexof ("?")! =-1) {            varstr = URL.SUBSTR (1); varSTRs = Str.split ("&");  for(vari = 0; i < strs.length; i++) {Therequest[strs[i].split ("=") [0]] = decodeuricomponent (strs[i].split ("=") [1]); }        }        returntherequest;}//If the fetch is garbled please see if unescape is used to decode the URL parameters, replace with decodeuricomponent or decodeURI, unescape and escape are about to be discarded// In addition: encodeURIComponent or encodeURI encoding is the same, for the entire URL, the former will be encoded in the URL;/?: @ & = + $, # The latter does not encode

JS get url parameter, and Chinese garbled problem

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.