javascript - 如何用ajax post一个url到php服务器?
此url是有有&符号的,用常规ajax post方式传到php后会把&符号前后分成一个个单独的参数...
<code>//如: url=http://localhost/app/index.php?c=show&a=index&from=weixin </code>
这个是一个参数,key是url,其它都是value(不是3个参数),请问如何才能将这个url完整地传到php呢?听说可以在js加密这个url,然后在php解密,但是我找了一下,js加密都要引用不少东西,请问有没有个简单的做法呢?
我试了使用转义符,上面的改成
<code>url=http://localhost/app/index.php?c=show\\&a=index\\&from=weixin </code>
php则会报错说找不到这个控制器...
回复内容:
此url是有有&符号的,用常规ajax post方式传到php后会把&符号前后分成一个个单独的参数...
<code>//如: url=http://localhost/app/index.php?c=show&a=index&from=weixin </code>
这个是一个参数,key是url,其它都是value(不是3个参数),请问如何才能将这个url完整地传到php呢?听说可以在js加密这个url,然后在php解密,但是我找了一下,js加密都要引用不少东西,请问有没有个简单的做法呢?
我试了使用转义符,上面的改成
<code>url=http://localhost/app/index.php?c=show\\&a=index\\&from=weixin </code>
php则会报错说找不到这个控制器...
...少年,老师没教过你 querystring 的参数一定要做 urlencode 的么=。=
<code>"url="+ encodeURIComponent("http://localhost/app/index.php?c=show&a=index&from=weixin"); </code>
PHP 后端按道理应该 $_GET['url']
是可以直接拿到正常的字符串的,如果没有的话请自行 urldecode 一次。
URL Encode一下参数再传就可以了
<code>url=encodeURIComponent("http://localhost/app/index.php?c=show&a=index&from=weixin") </code>
参考:http://stackoverflow.com/questions/332872/encode-url-in-javascript
额,刚刚看了一下url编码,使用这样的就可以解决问题了
<code>str.replace(/(&+)/g,'%26') </code>
就行了
然后顺便看到js有把字符串转换为url编码的方法encodeURIComponent()
,用这个也应该可以的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
