2011-05-11 14 views

回答

1

如果您正在使用jQuery:

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

如果沒有,你可以手動URL編碼的值使用encodeURIComponent功能:

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

如何解碼這個值在PHP ..? – reju 2011-05-11 13:44:49

+0

@reju,你不需要在PHP中解碼任何東西。如果您在PHP中對請求進行了正確的URL編碼,只需讀取POST集合中的值。 – 2011-05-11 13:46:27

+0

@DarinDimitrov謝謝。這對我也有幫助。所以加1 – Ram 2013-02-27 09:27:37

0

要在URL中使用&字符,必須先對其進行URL編碼。 PHP有一個功能可以做到這一點,稱爲urlencode,這可以提供幫助。爲了使上面的字符串的工作,它應該看起來像:

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

&變得%26。這裏是我寫的代碼找到這個:

<?php 

print urlencode('&'); 

?> 
相關問題