weixin_33691700 2014-02-06 07:49 采纳率: 0%
浏览 55

jQuery Ajax运行两次

So, I have this problem. I am using a plugin named jRating, it is esentially a rating system in jquery. My problem is, that onClick, the ajax request fires twice.

After searching a lot, I tried those things:

  1. I checked and double checked that the $(document).ready(function(){} and the jQuery shortcut $(function() {}); is not twice in the page.
  2. I also checked that the id of the call is unique.

So, here is my code:

jQuery:

$("#rating").jRating({
            step:true,
            length : 5,
            canRateAgain : true,
            nbRates : 3,
            onClick : function(element,rate) {

                var data = (rate, 1);
                $.ajax({
                    url: 'application/index/rate',
                    type: 'POST',
                    dataType: 'x-www-form-urlencoded',
                    async:false,
                    contentType: 'application/x-www-form-urlencoded',
                    data: rate,
                    success: function () {
                        console.log('SUBMIT WORKS');

                    },

                    error: function () {
                        console.log('There is error while submit');

                    }

                });  

            }
        });

pHTML:

<div id="rating" data-average="<?=$average //note that this is working everytime!?>" data-id="1"></div>

Thanks for any inputs!

EDIT: JsFiddle: http://jsfiddle.net/Je79U/ ;

To recreate the problem, click run, then go to console/network, clear all contents, then click anywhere on the yellow/orange bar, to rate, and see what happens. Thanks again for your time!

  • 写回答

1条回答

  • weixin_33682790 2014-02-06 08:05
    关注

    with reference of http://demos.myjqueryplugins.com/jrating/ , already jRating will work as ajax. So, that it takes ajax running twice

    Please check their demo website clearly.

    In that once you rate it will update the records to http://demos.myjqueryplugins.com/jrating/php/jRating.php

    and use the following version of jRating https://github.com/alpixel/jRating

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料