title: favorite button ajax
body: <p>i have problem with my ajax code it didn't work i don't know why.
  here is my code:
  this php code is in other page that named favourite.php</p>
  
  <p>i have problem with my ajax code it didn't work i don't know why.
  here is my code:
  this php code is in other page that named favourite.php</p>
  
  <pre><code> $test = $_SESSION['ww'];
  
      $x = $_SESSION['x'];
       $SelectQry2 = "select * from favorites where User_Id = ".$test." and User_Post = ".$x."";
         $slc = mysqli_query($link , $SelectQry2);
  
      if (mysqli_num_rows($slc)&gt; 0){
        $DeleteQry = "DELETE from favorites where User_Post = ".$x."";
        $del = mysqli_query($link , $DeleteQry);
        }else{
        $url = $_SERVER['REQUEST_URI'];
        $InsertQry = "insert into favorites";
        $InsertQry .="(`User_Id` ,`User_post`, `url`) VALUES";
        $InsertQry .=" ('$test' ,'$x', '$url')";
        $fav = mysqli_query($link, $InsertQry);
        }
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function(e){ 
   e.preventDefault();
   $("button").on("click", function(){  
   var data = $(this).serialize();
     $.ajax({ 
      type: "POST", 
   data: data,
      url: "favourite.php", 
      success: function(data){ 
        alert("Data Save: " + data); 
      },
      error: function(jqXHR, textStatus, errorThrown) 
      {
        alert("An ajax error occurred: " + textStatus + " : " + errorThrown);
      }
    }); 
  });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button&gt;favorite&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>