javascript-ajax-post-words,其中包含&;php中的符号与解码

javascript-ajax-post-words,其中包含&;php中的符号与解码,php,javascript,ajax,url,Php,Javascript,Ajax,Url,我正在尝试发送包含“&”的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: ''

我正在尝试发送包含“&”的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) {
        // ...        
    } 
});
如果没有,您可以使用以下函数手动对值进行URL编码:

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

要在URL中使用
&
字符,必须首先对其进行URL编码。PHP有一个函数来完成这个任务,这个函数名为。要使上述字符串正常工作,它应该如下所示:

search.php?region=Middle%20East%20%26%20Africa&city=&language=
其中
&
变为
%26
。以下是我编写的代码,用于查找:

<?php

print urlencode('&');

?>

@reju,您不需要在PHP中解码任何内容。如果在PHP中正确地对请求进行URL编码,只需从POST集合中读取值。