Ajax does not work

0

I have this code below in ajax:

    <script>
$("a").live("click", function(event) {      
      var targeturl = $(this).attr("href");

      $.ajax({
               type: "get",
               url: "/"+targeturl +"",
               data: "",
               dataType: "html",
               success: function(html){
                   jQuery('#add2').hide().html(html).fadeIn(1000);
                   location.reload();
               }

           });  // closing for  ajax
        event.preventDefault(); 

  });
</script>

And this code in PHP:

while($row = $stm->fetch())  {

  $color = completePayment($row["pago"]);

      "<div id=add9 align=middle style='color: {$color}; text-shadow: 1px 1px 1px black, 0 0 20px blue, 0 0 1px darkblue'>" .$row['pago'] . " <div id=add2 align=middle <br><br> <a id=add2 href=pago.php?id=". $row['id'] ."><img src=images/pago.png><a href=naopago.php?id=". $row['id'] . " ><img src=images/naopago4.png >

I just added the code that interests you. On the page there are two images (Pay and Not Pay), when I click on paid, it picks up the user ID and gives an update in the bank, setting the value SIM, and automatically this same value on the page, when not paid, does the same process. Back to the information NOT setting this value in the Bank. The problem that Ajax is not working, when I take Ajax the page executes and when I leave this code, it does not execute, I click on the images and nothing happens.

    
asked by anonymous 24.08.2017 / 23:15

1 answer

0

Leave only one loaded JQuery library.

And your Javascript script should look like this:

<script>
$("a").live("click", function(event) {      
  var targeturl = $(this).attr("link");

  $.ajax({
           type: "get",
           url: "/"+targeturl +"",
           data: "",
           dataType: "html",
           success: function(html){
               jQuery('#add2').hide().html(html).fadeIn(1000);
           }

       });  // closing for  ajax
    event.preventDefault(); 

 });
</script>

In php change it's like this:

 while($row = $stm->fetch())  {

 $color = completePayment($row["pago"]);

  "<div id=add9 align=middle style='color: {$color}; text-shadow: 1px 1px 1px black, 0 0 20px blue, 0 0 1px darkblue'>" .$row['pago'] . " <div id=add2 align=middle <br><br> <button id=add2 link=pago.php?id=". $row['id'] ."><img src=images/pago.png><button link=naopago.php?id=". $row['id'] . " ><img src=images/naopago4.png >
    
24.08.2017 / 23:47