简体   繁体   中英

passing and retrieving Latin Character in URL query string

I am having two HTML s step1.html and step2.html and I am passing latin value( envían )from step1.html to s tep2.html via URL query string by having the to be passed value( envían ) in input field value(which is in hidden state in step1.html .

I am getting the value of the query string parameter in step2.html using some utility function and I am displaying the value in one textbox but i got the value in textbox as different from the value passed see the screenshot.

在此处输入图片说明

Got encoded value for í , help me to get the same value í in step2.html also.

EDIT: One disadvantage is step2.html is twitter.com, there i cannot do any decoding. see the screenshot below 在此处输入图片说明

Thanks in advance for any help.

STEP1.html

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>

</head>

<body>
    <div class="">
        <form action="step2.html">
            <input type="submit" value="click to submit"/>

            <input type="hidden" name="val" value="envían" />
        </form>
    </div>  
</body>

Step2.html

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <script>

    var QueryString = function () {
      // This function is anonymous, is executed immediately and 
      // the return value is assigned to QueryString!
      var query_string = {};
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
            // If first entry with this name
        if (typeof query_string[pair[0]] === "undefined") {
          query_string[pair[0]] = pair[1];
            // If second entry with this name
        } else if (typeof query_string[pair[0]] === "string") {
          var arr = [ query_string[pair[0]], pair[1] ];
          query_string[pair[0]] = arr;
            // If third or later entry with this name
        } else {
          query_string[pair[0]].push(pair[1]);
        }
      } 
        return query_string;
    } ();

    function fngetval(){
        var val=QueryString.val;

        document.getElementById("status").value=val;
    }

    </script>

    <style>

    </style>
</head>

<body onload="fngetval();">
    <div class="">
        <textarea id="status" name="status" ></textarea>
    </div>  
</body>

You cannot have the í in a URL, thus why it is encoded into %ED .

You can either 1) use a POST form instead of the default GET . or 2) decode the value of the val variable. See this Stack Overflow question: JavaScript URL Decode function .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM