jQuery Ajax运行两次


                    

所以,我有这个问题。 我正在使用名为jRating的插件,它本质上是jquery中的评级系统。 我的问题是, onClick </ code>,ajax请求触发了两次</ strong>。 </ p>

搜索了很多之后,我尝试了这些事情:</ p>


  1. 我检查并再次检查了 $(document).ready(function(){} </ code>和jQuery快捷方式 $(function(){}); </ code> 页面中没有两次。</ li>
  2. 我还检查了呼叫的ID是否唯一。 </ li>
    </ ol>

    所以,这是我的代码:</ p>

    jQuery:</ strong> </ p>

      $(“#rating”)。jRating({
                 步骤:是的,
                 长度:5,
                 canRateAgain:是的,
                 nbRates:3,
                 onClick:function(element,rate){

                     var data =(rate,1);
                     $ .ajax({
                         网址:“应用程序/索引/费率”,
                         输入:“ POST”,
                         dataType:“ x-www-form-urlencoded”,
                         异步:假,
                         contentType:“ application / x-www-form-urlencoded”,
                         数据速率,
                         成功:功能(){
                             console.log('提交工作');

                         },

                         错误:功能(){
                             console.log('提交时出错');

                         }

                     });

                 }
             });
    </ code> </ pre>

    pHTML:</ strong> </ p>

      
    ” data-id =“ 1”> </ div>
    </ code> </ pre>

    感谢您的投入! </ p>

    编辑:JsFiddle: http://jsfiddle.net/Je79U/ ; </ p>

    要重新创建问题,请单击运行,然后转到控制台/网络,清除所有内容,然后单击黄色/橙色栏上的任意位置以进行评分,然后查看会发生什么情况。 感谢你的宝贵时间! </ p>
         </ div>

展开原文

原文

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个回答


参考 http://demos.myjqueryplugins.com/jrating/ ,已经jRating将 作为ajax工作。 因此,ajax运行两次</ p>

请清楚查看其演示网站。 </ p>

一旦您对其进行评分,它将把记录更新为 http://demos.myjqueryplugins .com / jrating / php / jRating.php </ p>

,并使用以下版本的jRating
https://github.com/alpixel/jRating </ p>
     </ div>

展开原文

原文

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐