-4

im making and update in mysql table when button click, the problem is ajax jquery not working sometimes. It works fine and somehow after x attempts it stop working and stars cancelling my petitions

the problem is after x number of attempts the success part of ajax object is not being used and im getting the STATUS (canceled) from network.

Hbassuki
  • 41
  • 6
  • You're looking for AJAX – Mike Sep 22 '15 at 18:02
  • You'll need an AJAX request in your else portion. Also I'd suggest against using PHP to echo out your JavaScript – Bill Effin Murray Sep 22 '15 at 18:04
  • how could i execute javascript without echo, within php? – Hbassuki Sep 22 '15 at 18:16
  • @Hbassuki Like this: `?> – Mike Sep 22 '15 at 18:57
  • @mike thanks im new to programming! so it doesnt matter how many times i open and close php tags , its always better than using the echo?? THANKS – Hbassuki Sep 22 '15 at 21:32
  • @Hbassuki No, not always better. But if you have a big block of HTML or JS that you want to echo, then yes. That way you should also get syntax highlighting if your editor supports it. – Mike Sep 22 '15 at 21:35
  • @Mike great! thank you a lot!!! yes im using ATOM and when using echo highlighting is not supported and its a bummer !! haha great! – Hbassuki Sep 22 '15 at 21:37

2 Answers2

0
$('.removeItem').click(function (event) {
    if (confirm('Are you sure you?')) {
        $.ajax({
            url: 'myUrl',
            type: "POST",
            data: {
                // data stuff here
             },
             success: function () {
                // does some stuff here...
            }
        });
    }
});

Use above code inside url there must be php page url...

Ali Mehdi
  • 884
  • 1
  • 11
  • 33
0

Pass these values to hidden fields. These fields are called through ajax to send data to next-page to update.

<input type='hidden' value="<?echo $costo_sem;?>" class="costosemanal">
<input type='hidden' value="<?echo $fi;?>" class="fechai">
<input type='hidden' value="<?echo $ff;?>" class="fechaf">

  echo "<script>
            var r = confirm('OK to update, CANCEL to do nothing');
            if(r === false){
             document.location.href = 'costos.php';
           }else{
            var costosemanal=$('.costosemanal').val();
            var fechai=$('.fechai').val();
            var fechaf=$('.fechaf').val();
            $.ajax({url:'UpdatePage.php?costosemanal='+costosemanal+'&fechai='+fechai+'&fechaf='+fechaf,cache:false,success:function(result){
                 alert('Updated');
            }});
           }
           </script>";

Add one UpdatePage.php to update your query.

UpdatePage.php

<?
$costosemanal=$_GET['costosemanal'];
$fechai=$_GET['fechai'];
$fechaf=$_GET['fechaf'];

$update = "UPDATE tbl_costos SET costo_semanal = '$costosemanal' WHERE fechai = '$fechai' AND fechaf ='$fechaf' ";

//Write Mysql Command To Update This Query

?>
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77