[英]How to send post data which contains php source with symbols like (+, *, /, -) and writing that data to a file using ajax request?
[英]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.