當我通過數字與函數參數發送使用Ajax它的工作正常,但是當我傳遞字符串,如下面給出它不接收在PHP頁面。
function loadState(country) {
$.ajax({
url: 'cardstate.php',
type: 'get',
data: { 'country': country },
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data) {
alert(data);
}
});
}
loadState("Pakistan")
// cardstate.php:
$country = $_GET['country'];
echo $country; // not receving string while when i put number its receiving
你不回來'json'在迴應中。我建議使用'dataType:'text''來代替 - 或者更好地在你的PHP中使用'$ json_encode()'來實際返回有效的JSON –
謝謝你的快速響應,實際上我需要以json格式返回數據來顯示它在
我不知道你在說什麼,但我的觀點是,你是*不*返回JSON當你應該是 –