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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献