简体   繁体   中英

ajax with php don't do anything

I wrote the code here in a hurry, I know I could have sql-injection, but in the version that I will publish I will fix everything, now I just have to understand why it doesn't work

i have this php page called user.php

<?php

$to = mysqli_query($con,"SELECT COUNT(username) FROM coins_logs WHERE id= '5';");
 while($totaleusertt = mysqli_fetch_array($to))
 {
   $totaleuser = $totaleusertt[0] - 1;

 }


 $contatore = 0;
 $query = mysqli_query($con,"SELECT username FROM coins_logs WHERE id= '5';");


  while($row = mysqli_fetch_array($query, MYSQLI_NUM))
 {
    $utentiU[$contatore] = $row[0];
    $contatore = $contatore + 1;

 }

  $prova = '<div class="table">
  <div class="table-header">
     <div class="header__item"><a id="name" class="filter__link" href="#">bids history</a>.         </div>

</div>
<div class="table-content"> 

    <div class="table-row">
        <div class="table-data">'. $utentiU[$totaleuser-1].'</div>

    </div>
    <div class="table-row">
        <div class="table-data">'.$utentiU[$totaleuser-2].'</div>

    </div>
    <div class="table-row">
        <div class="table-data">'. $utentiU[$totaleuser-3] .'</div>

    </div>
    <div class="table-row">
        <div class="table-data">'.$utentiU[$totaleuser-4].' </div>

    </div>
    <div class="table-row">
        <div class="table-data">'.$utentiU[$totaleuser-5].'</div>

    </div>
</div>  
       </div>';

     echo $prova;
     ?>

and I have this html page with this JS

     <head>
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
     </head>
    <div id="mytablepage">

   </div>
    <script type="text/javascript">

    $(document).ready(function(){
      function(){
           $.ajax({
                url: '/user.php',
                method:'POST',
                success:function(msg){
                      $('#mytablepage').html(msg);
                  }

             });
        }

   });



    </script>

but nothing happen, I tried to add a button for the ajax code, but I have the same result: nothing. what can I do to solve this?

You need call function

 $(document).ready(function() { (function() { $.ajax({ url: '/user.php', method: 'POST', success: function(msg) { $('#mytablepage').html(msg); } }); }()) });

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