dimanche 28 juin 2015

How to get information in jquery function from the php file

Hello guys my question is how to get an db information (in my case points just a number) from the php file to the jquery ajax script so here is my jquery:

function rate_down(id) { 
    var id = id;
//submit data to php script

    var data = {
      "id": id,
    };

    $.ajax({
      type: "POST",
      url: "rating.php",
      data: data,
      success: function(response) {

      var currentValue = /* here i want to put the db number */
      var newValue = +currentValue - 1;
      $("#points_"+id).text(newValue);




      },
      error: function(jqXHR, textStatus, errorThrown){
        alert(errorThrown);
      } 
    });
};

And i want my raiting.php im not sure if i shoud post it becouse its usless but here is my mysql query in raiting.php:

$pic_id = (int) $_REQUEST['id'];
mysql_query = mysql_query"SELECT points FROM `photos` WHERE `id` = '$pic_id'";

Aucun commentaire:

Enregistrer un commentaire