編輯:固定_錯字(2次),加頭,仍在記錄100jQuery的基本AJAX GET + PHP回報
當點擊我的JavaScript的按鈕,我射擊這個功能(參數:100)
ajaxManager = new AjaxManager();
ajaxManager.requestHexContent(100);
function AjaxManager(){
this.requestHexContent = function(id){
$.ajax({
type : 'get',
url : 'simulator/hexFiller.php',
dataType : 'json',
data: {
gameid: id,
},
success : function(ret){
console.log(ret);
},
error : function(){
alert("error")
}
});
},
}
這是我hexFiller.php
<?php
header('Content-Type: application/json');
$ret;
if (isset($_GET["gameid"])){
if ($_GET["gameid"] == 100){
$ret = 200;
}
else {
$ret = "error";
}
}
echo json_encode($ret);
?>
現在,我會希望發生的事情是我的瀏覽器來登錄「200」到控制檯,或「錯誤」。相反,它將「100」記錄到控制檯。
有人可以向我解釋我思想中的根本錯誤嗎?
你是如何調用該函數?點擊時觸發此功能是否可以獲得代碼? –
編輯了代碼,還在requestHexContent() –
的調用中添加了它的工作,這裏工作得很好。此前它出現錯誤並提醒「錯誤」。當我將$ GET更改爲$ _GET時。它返回了200. 還有什麼你想要的?我應該粘貼代碼嗎? –