我有一個ajax函數應該發佈一些數據到另一個頁面,但它似乎並沒有因爲某些原因發佈。ajax沒有發佈到頁面
我不知道爲什麼這不起作用,我一直在過去的一個小時裏看它。
Ajax的功能
$(document).ready(function()
{
$('.rate').click(function(){
var ratingId = $('#ratingID').val();
var clickBtnValue = $(this).val();
var ajaxurl = 'ProcessRating.php',
data = {'action': clickBtnValue, 'ratingID': ratingId};
$.post(ajaxurl, data, function (response)
{
alert("action performed successfully");
});
});
});
在主頁
<?php
session_start();
echo $_SESSION["messege"];
?>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">
</script>
<script>
//The Ajax function is here
</script>
</head>
<body>
<form>
<input type="hidden" class="rate" id="ratingID" name="ratingID" value =
"<?php echo $article->getId()?>" />
<input type="submit" class="rate" name="1" value="1" />
<input type="submit" class="rate" name="2" value="2" />
<input type="submit" class="rate" name="3" value="3" />
<input type="submit" class="rate" name="4" value="4" />
<input type="submit" class="rate" name="5" value="5" />
</form>
</body>
在頁面ProcessRating.php
<?php
session_start();
$_SESSION["messege"] = "got This far";
if (isset($_POST['action']))
{
$id = $_POST['ratingID'];
switch ($_POST['action']) {
case '1':
updateRating($db, $id, "oneStar");
break;
case '2':
updateRating($db, $id, "twoStar");
break;
case '3':
updateRating($db, $id, "threeStar");
break;
case '4':
updateRating($db, $id, "fourStar");
break;
case '5':
updateRating($db, $id, "fiveStar");
break;
}
$rating = getAvgRating($db, $id);
updateArticleRating($db, $id, $rating);
}
你看過控制檯以及使用php的錯誤報告嗎? –
我沒有看到你連接到ProcessRating.php上的數據庫的任何地方? – RiggsFolly
它甚至沒有,因爲它不會迴應會話消息,所以我可以看到我到了下一頁 –