开发者

Jquery and PHP rating function problem

I know that I was already posted similar question but I just can't find the answer and figure it out how to solve this problem.

I'm trying to customize Jquery Star Rating plugin (link text) but I do not know what to do to show the message based on response of PHP s开发者_开发问答cript.

Jquery script successfully send rating data to PHP scripts that query the database and based on that echo message of proper or improper rating.

What should I add to an existing JS code so I can get echo from PHP and base on that write a message on some DIV beside rating star?

Jquery:

$('#gal').rating('gl.php?gal_no=<?=$gal_no;?>&id=<?=$id;?>', {maxvalue:10,increment:.5, curvalue: <?=$cur;?>});

Simplified PHP code:

$br=mysql_query("SELECT count(gal) as total FROM ...")
if ... {
echo '0';
}
else echo '1';
}

Jquery code successfully transmitted data to PHP script and when the PHP done with checking data echo the result ('1' or '0'). How can I get this PHP result back to Jquery and based on them write a message? Something like:

if(data=="1")
{
$("#error").show("fast").html('not correct').css({'background-color':'#F5F5F5','border-color' : '#F69'});
}else{
$("#error").show("fast").html('correct').css({'background-color' : '#FFF','border-color' : '#3b5998'}); 
}

If someone has an idea...I would appreciate it.


You would have to modify the source of the rating plug-in, as it does not provide any way for you to handle return values of your script. Read the documentation of jquery.post method in jquery, and then try to understand rating's code. Notice that when calling post method rating plugin doesn't provide a callback method (in other words it just doesn't care what your php script returns). You could try to modify the code in such way, that it allows you to register your own callback method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜