0

I don't see what i am doing wrong. The second ajax call doesn't work, like the first

     $(".payment").click(function(){
     visitorID = $(this).attr('id');
     alert("Modal says "+visitorID);
     $.ajax({ url: 'update.php',
         data: {action: visitorID},
         type: 'post',
         success: function(output) {
                      alert(output);
                      window.location.reload(); //reload so we see the updated values

                  },
        });     
});//#end click
$(".generateInvoice").click(function(){
     barcode = $(this).attr('barcode');
    alert("Modal says "+barcode);
     //console.log('hello');
     $.ajax({ url: 'generateInvoice.php',
         data: {action: barcode},
         type: 'post',
         success: function(output) {
                      alert('hi '+output);
                     //console.log('hie');
                      //window.location.reload(); //reload so we see the updated values

                  },
        });     
});//#end click

With payment i see both alert boxes, but with generateInvoice i only see the first alert box. For testing purpose i have made generateInvoice.php just reading

echo ' there does it work';
die();

But with .generateInvoice the alert in the $.ajax doesn't show

Any info?

alex
  • 4,804
  • 14
  • 51
  • 86
  • 1
    Add a [error handler](http://api.jquery.com/ajaxError/) and see what the problem is. – epascarello Mar 13 '13 at 16:46
  • 1
    Do **not** use `alert()`, use [`console.log()`](http://stackoverflow.com/questions/4743730/what-is-console-log-and-how-do-i-use-it) – Dom Mar 13 '13 at 16:46
  • 1
    Have you watched the request with fiddler/your browser dev tools to see what the response from that request contains? If an error is being returned the `success` wont be executed – Jamiec Mar 13 '13 at 16:46
  • This may be the problem: window.location.reload(); – Todd Murray Mar 13 '13 at 16:47
  • @ToddMurray, the reload has nothing to do with it. The OP was showing two methods that are unrelated other than the basic code. – epascarello Mar 13 '13 at 16:48
  • 1
    @Dom - cant see how using an alert would make a difference... good practice to not use alert-based debugging as the console is richer but it wont make any difference to the problem. – Jamiec Mar 13 '13 at 16:49
  • @Jamiec I agree. Sorry, should've written "Side Note:" prior. My mistake! – Dom Mar 13 '13 at 16:49
  • The issue may be with your php file. Try replacing "generateInvoice.php" with "update.php". – ATOzTOA Mar 13 '13 at 17:12
  • hello guys, already tried console.log and i am watching the chrome > developer tools >network tab. generateInvoice.php doesn't seemed to be called at all. btw: i am using both(alert +console.log) for error checking – alex Mar 13 '13 at 17:14

1 Answers1

0

tx for thinking along, but i found my stupid mistake.

It turn out in the HTML the button tag didn't have the type declared, so i added

type="button" 

and now the ajax part is being triggered/called :)

as the first alert was showing it didn't cross my mind

regards

alex
  • 4,804
  • 14
  • 51
  • 86