2014-02-06 72 views
0

所以,我有這個問題。我使用名爲jRating的插件,它本質上是jquery中的評分系統。我的問題是,該onClick,阿賈克斯請求火災兩次jquery ajax運行兩次

搜索了很多,我想這些事情:

  1. 我查和雙重檢查的$(document).ready(function(){}和jQuery的快捷方式$(function() {});是不是兩次在頁面中。
  2. 我也檢查了通話的ID是唯一的。

所以,這裏是我的代碼:

的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> 

感謝任何投入!

編輯:的jsfiddle:http://jsfiddle.net/Je79U/;

重現問題,單擊運行,然後再安慰/網絡,清除所有內容,然後單擊任意位置的黃/橙色條上,以速度,看看會發生什麼。感謝你的寶貴時間!

+0

小提琴請.. –

+0

請提供撥弄鏈接 –

+0

OK,我心底嘗試做小提琴,馬上回來! –

回答