php - for looping in jquery -
in php have such code in while loop...
$result = mysql_query("select * wallpost order wallpostid desc"); while($row = mysql_fetch_assoc($result)){ $rate = "<div class=\"example-".$id." \" data-postid=\"".$id."\"></div></br>post id: <span class=\"example-rating-".$id."\">".$id."</span>"; }
jquery is...
$(document).ready(function() { $('[class^="example-"]').not('[class^="example-rating-"]').ratings(3).bind('ratingchanged', function (event, data) { var child = $(this).find('[class^="example-rating-"]'); child.text(data.rating); $.post('count.php', { rate: data.rating, wallpostid: jquery(this).data("postid") }, function (data) { alert(data); }); });
for value null value, if replace
var = $('.example-rating-50').html(); //let wallpostid 50
it can pass value 50 count.php if let have 2 wallpostid 22 , 50 (loop while loop ) if rate wallpostid 22 want pass value of $id=22 php jquery , $.post count.php. same if rate wallpostid=50.
you dont need loop in javascript, there selectors can handle this, instance class^=
php
$rate = "<div class=\"example-".$id." \" data-postid=\"".$id."\"></div></br>post id: <span class=\"example-rating-".$id."\">".$id."</span>";
js
//find elements have class starting 'example-' not example-rating- $('[class^="example-"]').not('[class^="example-rating-"]').ratings(3).bind('ratingchanged', function (event, data) { //find child element has class starting 'example-rating-' var child = $(this).find('[class^="example-rating-"]'); child.text(data.rating); $.post('count.php', { rate: data.rating, wallpostid: jquery(this).data("postid") }, function (data) { alert(data); }); });
Comments
Post a Comment