我使用的是在此站点上找到的源代码: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 中放置了将“成功”写入数据库的代码,这样我就可以测试它是否正在执行 - 但显然没有。
有没有人有什么想法?
谢谢!
jack
编辑:刚刚尝试使用此代码代替我之前使用的代码:
$('#rating_'+rid).load('send.php', function () {alert('Load was performed.');});
对话显示正确,所以我相信它能正常工作。
供引用,send.php的PHP代码为:
<?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);
// $total_ratings = $row['total_ratings'];
$total_ratings = $query->row('total_ratings');
$total_rating = $query->row('total_rating');
$current_rating = $query->row('rating');
$new_total_rating = $total_rating + $rating;
$new_total_ratings = $total_ratings + 1;
$new_rating = $new_total_rating / $new_total_ratings;
// Lets run the queries.
$this->db->query("UPDATE test SET total_rating = '".$new_total_rating."' WHERE id = '".$id."'");
$this->db->query("UPDATE test SET rating = '".$new_rating."' WHERE id = '".$id."'");
$this->db->query("UPDATE test SET total_ratings = '".$new_total_ratings."' WHERE id = '".$id."'");
echo"<div class='highlight'>Thanks for your vote!</div>";
}
}
?>
抱歉,有点乱,但我一直在将默认的 PHP 代码迁移到我的 CodeIgniter 库中。
最佳答案
首先要检查来自 Web 服务器的访问和错误日志,以查看请求是否确实到达了 Web 服务器。
关于php - jQuery, PHP : Calling a PHP script from jQuery, 但它似乎没有执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2349162/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r