Solve the problem that JS parameter contains Chinese garbled characters when passing parameters in URL

Source: Internet
Author: User

1. The reference page JavaScript code:

function Go_mark (id,jobname,headimgurl,nickname) {        window.location.href = "mark.html?id=" +id+ "&jobname=" + encodeURI (JobName) + "&headimgurl=" +headimgurl+ "&nickname=" +encodeuri (nickname);    }

2. Receive the Parameters page:

    $ (function () {        var postdata = Getrequest ();        $ (". Release_num em"). HTML (postdata.jobname);        $ ("#img"). attr (' src ', postdata.headimgurl);        $ (". Nick_name"). HTML (postdata.nickname);           })    function Getrequest () {        var url =decodeuri (decodeURI (Location.search));//Get URL "?" String, using two times Decoderui decoding        var therequest = new Object ();        if (Url.indexof ("?")! =-1) {            var str = url.substr (1);            STRs = Str.split ("&");            for (var i = 0; i < strs.length; i++) {                therequest[strs[i].split ("=") [0]] = unescape (strs[i].split ("=") [1]); 
   
    }            return therequest;        }    }
   

Note: The code here is used in conjunction with JQ, which is required to refer to the JQ file.

Original source: http://www.cnblogs.com/xiaodongaini/p/5031166.html

Solve the problem that JS parameter contains Chinese garbled characters when passing parameters in URL

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.