2017-08-24 108 views
1

當我通過數字與函數參數發送使用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 
+1

你不回來'json'在迴應中。我建議使用'dataType:'text''來代替 - 或者更好地在你的PHP中使用'$ json_encode()'來實際返回有效的JSON –

+0

謝謝你的快速響應,實際上我需要以json格式返回數據來顯示它在