2 回答

TA貢獻1799條經(jīng)驗 獲得超9個贊
在您的 Ajax 調用中,您將方法指定為POST. 但是在您的 PHP 頁面中,您正在嘗試使用請求來獲取請求$_GET['blog_title'],這就是您收到未定義變量錯誤的原因。
而不是$_GET你應該使用$_POST或$_REQUEST。也就是說,更換
$blog_title = $_GET['blog_title'];
和
$blog_title = $_POST['blog_title'];
或者
$blog_title = $_REQUEST['blog_title'];
在文檔中閱讀有關$_REQUEST和$_POST的更多信息。
或者
您可以如下更改您的 ajax 請求。
$.ajax({
method:"GET", //changed method to GET
url:"comment.php",
data:{
"comment":comment,
"commenter_name":username,
"commented_post":title,
},
dataType = "json",
success: function(result){
alert("Comment posted.");
$("#record").html(result);
}
});

TA貢獻1803條經(jīng)驗 獲得超6個贊
像 Lal 回答一樣,首先需要轉換為 GET 方法,然后需要聲明 blog_title 參數(shù)。
<script src = "js/jquery.js"></script>
<script>
function Comment(comment, username, title){
//alert(search + " " + filter);
$.ajax({
method:"GET", // Changed method to GET
url:"comment.php",
data:{
"comment":comment,
"commenter_name":username,
"commented_post":title,
"blog_title":title //You must declare the blog_title parameter here
},
dataType = "json",
success: function(result){
alert("Comment posted.");
$("#record").html(result);
}
});
}
</script>
- 2 回答
- 0 關注
- 195 瀏覽
添加回答
舉報