Passing JSON data in a URL

Source: Internet
Author: User

Are we passing data in URLs that are generally xx.aspx? a=1&b=2&c= you pass the Chinese in this way is OK, we use request.querystring["C" in the background to accept it. The browser will automatically decode it for us.

If the parameter is too many, so stitching is not very convenient, this time we can put all the parameters and values in the JSON format, and then the value xx.aspx?json={"1", 1, "2", "2"}, if written like this, When accepted, only one parameter is accepted.

JSON in the URL to the value of considerations:

1, the JSON string needs to be encoded and then passed

2, if the JSON string appears in Chinese, we can not decode in the background

View Listjson

For example:

<div> <a href="Webform1.aspx?jsondata=<%=json%>"> Background Write josn value </a> <div id="Test"style="width:150px; height:150px; border:solid 1px red;">JS Transfer value</div> </div> <script src=".. /jquery.min.js"></script> <script>            $("#test"). Click (function () {varJSON ={Name:"Li MoU", Age: A, like:"Movies"} document.location.href="webform1.aspx?jsondata="+ Escape (json.stringify (JSON));//encoding pass -through value            }); </script>

Page effects

Accept page:

Background acceptance

We can not decode Chinese, only use data["Name" method to get Chinese.

JS Accept

Effect:

① Click Background to pass JSON background decoding Chinese does not come out

② Click JS to pass the value of the background can decode the success

We can then use JS to get this JSON, and turn it into an object

Passing JSON data in a URL

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.