[英]Jquery / PHP - ajax post and encoding
I m trying to send a url string using ajax post but dont not know why the string is auto encoding (%25) or omitting 我正在尝试使用ajax发布发送url字符串,但不知道为什么该字符串会自动编码(%25)或省略
url = http://www.domain.com.br/berco-elegance-wave-verde-ayoba%2521-6343.html url = http://www.domain.com.br/berco-elegance-wave-verde-ayoba%2521-6343.html
php receive: http://www.domain.com.br/berco-elegance-wave-verde-ayoba%21-6343.html php接收: http : //www.domain.com.br/berco-elegance-wave-verde-ayoba%21-6343.html
I check with Firebug the post data and the url string is already changed: POST DATA url: http://www.domain.com.br/berco-elegance-wave-verde-ayoba%21-6343.html 我使用Firebug检查发布数据,并且url字符串已更改:POST数据url: http : //www.domain.com.br/berco-elegance-wave-verde-ayoba%21-6343.html
My jquery code: 我的jQuery代码:
function save_competitor() {
$.ajax({
type: "post",
url: "<?php echo base_url();?>admin/storeproduct/insert_competitor",
data: "url="+$("#url"),
dataType:"json",
contentType : "application/x-www-form-urlencoded; charset=UTF-8",
success: function (data) {
if(data.success){
alert('ok');
}else{
alert('error');
}
},
error: function (request, status, error) {
if(status=='parsererror')
window.location.href = 'auth/login/';
}
});
}
HTML: HTML:
<input type="text" id="url" name="url" value="http://www.domain.com.br/berco-elegance-wave-verde-ayoba%2521-6343.html"/>
isnt $("#url") returning an Element? 是不是$(“#url”)返回一个元素?
$("#url").val()
or
$("#url").attr('href')
You get your data
from html text already encoded. 您可以从已编码的html文本中获取data
。 Can you show us what the part of your $("#url") html code look like ? 您能告诉我们$(“#url”)html代码的一部分是什么样吗?
EDIT : 编辑:
Function : 功能说明
function urldecode(str) {
return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}
Usage : 用法:
data: "url="+urldecode($("#url").text());
URL Endoding References: URL Endoding参考:
space %20
! %21
" %22
# %23
$ %24
% %25
& %26
' %27
( %28
) %29
* %2A
+ %2B
, %2C
- %2D
. %2E
/ %2F
.....
encodeURIComponent and decodeURIComponent will resolve this issue encodeURIComponent和encodeURIComponent将解决此问题
encodeURIComponent(url);
decodeURIComponent(url)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.