JavaScript-How do I post a URL to a PHP server with Ajax?

Source: Internet
Author: User
This URL is a & symbol, the normal Ajax post to PHP will be the & symbol before and after a separate parameter ...

//如:url=http://localhost/app/index.php?c=show&a=index&from=weixin

This is a parameter, the key is the URL, the other is value (not 3 parameters), how can I upload this URL completely to PHP? I heard that you can encrypt this URL in JS, and then decrypt in PHP, but I looked for a bit, JS encryption to quote a lot of things, is there a simple way?

I tried to use the escape character, which was changed to

url=http://localhost/app/index.php?c=show\\&a=index\\&from=weixin

PHP will say that the controller could not be found ...

Reply content:

This URL is a & symbol, the normal Ajax post to PHP will be the & symbol before and after a separate parameter ...

//如:url=http://localhost/app/index.php?c=show&a=index&from=weixin

This is a parameter, the key is the URL, the other is value (not 3 parameters), how can I upload this URL completely to PHP? I heard that you can encrypt this URL in JS, and then decrypt in PHP, but I looked for a bit, JS encryption to quote a lot of things, is there a simple way?

I tried to use the escape character, which was changed to

url=http://localhost/app/index.php?c=show\\&a=index\\&from=weixin

PHP will say that the controller could not be found ...

... Juvenile, the teacher did not teach you querystring parameters must be done UrlEncode =. =

"url="+ encodeURIComponent("http://localhost/app/index.php?c=show&a=index&from=weixin");

PHP back-end should be reasonable $_GET['url'] to get the normal string, if not, please self-urldecode once.

URL encode the parameters and then pass it.

url=encodeURIComponent("http://localhost/app/index.php?c=show&a=index&from=weixin")

Reference: Http://stackoverflow.com/questions/332872/encode-url-in-javascript

Well, just looked at the URL code, using this can solve the problem

str.replace(/(&+)/g,'%26')

It's all right.

And then by the way to see JS has to convert the string to URL encoding method encodeURIComponent() , this should also be possible

  • 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.