当我通过数字与函数参数发送使用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当你应该是 –