Sorry if this is a question with a obvious answer but my knowledge with Jquery is very limited and I don’t have any idea how to debug this.
Basicaly on my site I have a ranking script (see here working nfrases.com in the middle box) that reads if the user clicks up or down and then a jquery script picks the vote, sends it to ajax.php that do the mySQL queries and it refreshes the $rating value. I followed a tutorial so everything went pretty smooth to achieve this.
Now I’m trying to reproduce it at http://www.nfrases.com/modelo2.php?tag_nome=vida but nothing works … already tried a million variations (not realy knowing what I was doing) and nothing worked. The jquery script is out of the scripts.js for more easily debbuging but I’ll paste here the the problematic areas so I can better help you help me!
Thanks in advance!
HTML part:
<ul id="caixacontainer2">
<li id="m<?php echo $id_frase ?>">
<div class="vote2 <?php verification that returns "active" or "inactive" ?>">
<span class="up"></span>
<span class="down"></span>
<span class="rating2"><?php echo $rating ?></span>
</div>
</li>
</ul>
jQUERY part:
$(document).ready(function(){
var ul = $('ul.caixacontainer2');
$('div.vote2 span').live('click',function(){
var elem = $(this),
parent = elem.parent(),
li = elem.closest('li'),
ratingDiv = li.find('.rating2'),
id_frase = li.attr('id').replace('m',''),
v = 1;
if(parent.hasClass('inactive')){ return false; }
parent.removeClass('active').addClass('inactive');
if(elem.hasClass('down')){ v = -1; }
ratingDiv.text(v + +ratingDiv.text());
var arr = $.makeArray(ul.find('li')).sort(function(l,r){ return +$('.rating2',r).text() - +$('.rating2',l).text(); });
ul.html(arr);
$.get('ajax.php',{action:'vote',vote:v,'id_frase':id_frase});
});
});
Also … is it possible the problem derive from already having a $(document).ready(function(){ inside the file scripts.js ?
Thanks again, appreciate all the help you can give me debbuging this as I feel completely lost here!
Cheers
As others have said, you should do some debugging. See what gets executed and what not. It seems to me this line is erroneous and that the execution stops there:
One
+is redundant.Also: for requests to change things on the server you are supposed to use
post(notget). This might not matter practically, but sometimes it does (whengetrequests are configured to be cached and therefore not sent again, whilepostrequests are not).