繁体   English   中英

javascript ajax词,其中包含&符号并在php中解码

[英]javascript ajax post words which contains & symbol and decode in php

我试图发送包含'&'的ajax帖子。

search.php?region=Middle%20East%20&%20Africa&city=&language=

但它仅在php端返回“中东”

请帮我

如果您使用的是jquery:

$.ajax({
    url: 'search.php',
    type: 'POST',
    data: { region: 'Middle East & Africa', city: '', language: '' },
    success: function(result) {
        // ...        
    } 
});

如果没有,您可以使用encodeURIComponent函数手动对值进行URL编码:

var region = encodeURIComponent('Middle East & Africa');
// TODO: send the encoded value

要在URL中使用&字符,必须首先对其进行URL编码。 PHP具有执行此功能的功能,称为urlencode ,可以提供帮助。 要使上面的字符串起作用,它应该类似于:

search.php?region=Middle%20East%20%26%20Africa&city=&language=

其中&变为%26 这是我为找到该代码而编写的代码:

<?php

print urlencode('&');

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM