Home  >  Article  >  Backend Development  >  ajax GET请求参数莫名丢失问题

ajax GET请求参数莫名丢失问题

WBOY
WBOYOriginal
2016-06-06 20:40:562853browse

<code>GET http://hong.dev.meituan.com/index.php?c=Search&a=associate&q=%20

200 OK
        24ms    
jquery-....min.js (第 4 行)
参数头信息响应HTMLCookies
a   associate
c   Search
q   
</code>

这是ajax GET请求的URL地址,为什么当参数q为中文的时候,在firebug下面看q的参数为空呢?地址上有值啊,我传的是中文,为什么会给编码了?事实上这个参数为“奶”

回复内容:

<code>GET http://hong.dev.meituan.com/index.php?c=Search&a=associate&q=%20

200 OK
        24ms    
jquery-....min.js (第 4 行)
参数头信息响应HTMLCookies
a   associate
c   Search
q   
</code>

这是ajax GET请求的URL地址,为什么当参数q为中文的时候,在firebug下面看q的参数为空呢?地址上有值啊,我传的是中文,为什么会给编码了?事实上这个参数为“奶”

地址上的q=%20是空格 所以下面显示的也是空格

所以你的服务端收到的请求中参数q也是个空格,并不是中文

先确认下哪个环节出了问题

我认为你需要的是 encodeURIComponent 或者 encodeURI 方法对请求的地址进行url编码。具体请参考
encode-url-in-javascript

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:phper进阶疑问Next article:php导入.ait文件??