我有一個PHP函數,給出了一個警告的反應,如果結果是> 0
但我得到一個空的警告,如果結果是0
阿賈克斯結果依賴於PHP結果
我怎樣才能停止?
function urlCheck()
{
$website_id = $this->input->post('website_id');
$post_title = $this->input->post('post_title');
$urlCheck = $this->page_model->pageURLCheck($post_title, $moviesparx_website_id);
if($urlCheck > 0)
{
echo "This page name already exists";
}
}
的jQuery的Ajax:
$.ajax({
url:url,
data:data ,
type: 'POST',
success: function (resp) {
alert(resp);
},
error: function (resp) {
console.log(data);
}
});
成功被棄用使用.done()代替...也console.log(resp)看看你回來。另一件事是......應該打印的警報「這個頁面名稱已經存在?」如果是這樣你需要將其轉換爲json並正確地將標題應用於它。 – xlordt
這是因爲您只在結果> 0時發送響應 –
@xlordt爲什麼他需要將其轉換爲JSON?沒有轉換,'resp'將只是PHP回聲的文本。 – Barmar