开发者

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

开发者 https://www.devze.com 2023-03-04 22:26 出处:网络
i m trying to send ajax post which contains \'&\'. search.php?region=Middle%20East%20&%20Africa&city=&language=

i m trying to send ajax post which contains '&'.

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

but 开发者_运维百科it return 'Middle East' only in php side

Please help me


If you are using jquery:

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

If not you could manually URL encode the value using the encodeURIComponent function:

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


To use the & character in a URL, you must first URL encode it. PHP has a function for doing this called urlencode, which can help. To make the above string work, it should look like:

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

Where the & becomes %26. Here's the code I wrote to find this:

<?php

print urlencode('&');

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消