大佬教程收集整理的这篇文章主要介绍了jQuery,PHP:从jQuery调用PHP脚本,但它似乎没有执行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用此站点上的源代码:http://webtint.net/tutorials/5-star-rating-system-in-php-mysql-and-jquery/comment-page-1/#comment-2562
一个很棒的资源,我想你们都会同意,但我的问题是我的Javascript似乎并没有真正执行PHP脚本……
当我在Chrome的调试器中为倒数第二行(之前)添加断点时; ):
$("[id^=rating_]").children("[class^=star_]").click(function() {
var current_star = $(this).attr("class").split("_")[1];
var rid = $(this).parent().attr("id").split("_")[1];
$('#rating_'+rid).load('http://localhost:8888/fivestars/send.PHP', {rating: current_star, id: riD});
});
正如您所期望的那样,它会在断点处成功停止.但是我只是无法让send.PHP实际做任何事情,它根本就不会!正如您从代码中看到的,我使用了绝对URL,但它不适用于相对URL或仅在该位置使用send.PHP.我已经在send.PHP中放置了代码,将“成功”写入数据库,这样我就可以测试它是否正在执行 – 但显然不是.
有没有人有任何想法?
谢谢!
插口
$('#rating_'+rid).load('send.PHP', function () {alert('Load was performed.');});
对话框显示正确,所以我确信它正在工作.
<?PHP
$rating = (int)$_POST['rating'];
$id = (int)$_POST['id'];
$this->db->query("INSERT INTO code (rating) VALUE (8)");
$query = $this->db->query("SELECT * FROM code WHERE id = '".$id."'");
while($query->row()) {
if($rating > 5 || $rating < 1) {
echo"rating can't be below 1 or more than 5";
}
elseif(isset($_COOKIE['rated'.$id])) {
echo"<div class='highlight'>You've already Voted, sorry!</div>";
}
else {
setcookie("rated".$id, $id, time()+60*60*24*365);
// $@R_16_10586@l_ratings = $row['@R_16_10586@l_ratings'];
$@R_16_10586@l_ratings = $query->row('@R_16_10586@l_ratings');
$@R_16_10586@l_rating = $query->row('@R_16_10586@l_rating');
$current_rating = $query->row('rating');
$new_@R_16_10586@l_rating = $@R_16_10586@l_rating + $rating;
$new_@R_16_10586@l_ratings = $@R_16_10586@l_ratings + 1;
$new_rating = $new_@R_16_10586@l_rating / $new_@R_16_10586@l_ratings;
// Lets run the queries.
$this->db->query("updatE test SET @R_16_10586@l_rating = '".$new_@R_16_10586@l_rating."' WHERE id = '".$id."'");
$this->db->query("updatE test SET rating = '".$new_rating."' WHERE id = '".$id."'");
$this->db->query("updatE test SET @R_16_10586@l_ratings = '".$new_@R_16_10586@l_ratings."' WHERE id = '".$id."'");
echo"<div class='highlight'>Thanks for your Vote!</div>";
}
}
?>
对不起,这有点乱,但我一直在将默认的PHP代码迁移到我的CodeIgniter库.
解决方法:
要检查的第一件事是来自Web服务器的访问和错误日志,以查看请求是否实际到达Web服务器.
以上是大佬教程为你收集整理的jQuery,PHP:从jQuery调用PHP脚本,但它似乎没有执行全部内容,希望文章能够帮你解决jQuery,PHP:从jQuery调用PHP脚本,但它似乎没有执行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。