简体   繁体   中英

Ajax doesn't connect with database

I have a problem with ajax . I want to make a simple vote system but I have problems with it:

<div id="button_up" onclick="vote_plus(1,$id)"></div>
<div id="button_down" onclick="vote_plus(-1,$id)"></div>

votesystem.php

<?php 
include 'connection.php';
connection();
$page_id=$_GET['page_id'];
$rate=$_GET['rate'];
mysql_query("UPDATE img SET suma=suma+$rate, ocen=ocen+1 WHERE id=$page_id");

?>

and main function:

function vote_plus(rate,page_id)
    {   
    alert('rate='+rate+'id='+page_id);
    $.ajax({
      url: 'vote_system.php',
      type: 'post',
      data: {rate:rate, page_id:page_id},
      success: function(output) 
      {
          alert('success, server says '+output);
      }, error: function()
      {
          alert('something went wrong, rating failed');
      }
   });


    }

I tried to do it like on this link: JavaScript to update MySQL?

All i had to do was to load jQuery and change these get to POST. Thanks for help and your time

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM