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:
- I checked and double checked that the
$(document).ready(function(){}
and the jQuery shortcut$(function() {});
is not twice in the page. - 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!