开发者

Jquery post and get data from PHP

Jquery code looks like:

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

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? Some thing like:

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


You havent shown your full code for the rating plugin so i dont know where you want to make your ajax call at, but that call should look something like this:

$.post('gl.php', {
  data: {
     gal_no: '<?=$gal_no;?>',
     id: '<?=$id;?>'
  },
  function(data) {
    if(parseInt(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'}); 
    }
  }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜