Ajax and events

Ajax and events

Hello,

So I've been looking around in regards to my problem, and though others seem to have the same issue,I am just not finding a solution.  So, I am hoping I can get a direct answer to help me out here.

End state: after executing Ajax, all jq events cease to function.  Below I have a test file (named test.php), to illustrate:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Page Title</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css"/>
  7. <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  8. <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
  9. <style type="text/css">
  10. </style>
  11. <script type="text/javascript">
  12. $(document).ready(function(){
  13. $('#alertbutton').bind('click', function(event){
  14. alert("test button clicked");
  15. });
  16. $("#ajaxbutton").click(function(){
  17. $.ajax({type:"post", url:"test.php", data:"test=1",
  18. success:function(data){
  19. alert("AJAX complete.");
  20. $.mobile.changePage( "test.php", {
  21. transition:"flip",
  22. changeHash:false,
  23. allowSamePageTransition:true,
  24. reloadPage:true
  25. });
  26. }
  27. });
  28. });
  29. });
  30. </script>
  31. </head>
  32. <body>
  33. <div data-role="page">
  34. <div data-role="content">
  35. <button type="button" id="alertbutton">Alert() button</button>
  36. <button type="button" id="ajaxbutton">AJAX button</button>
  37. </div>
  38. </div>
  39. </body>
  40. </html>

With the above code, when I click "AJAX button", the page loads itself and jq events never fire again... at least, until I F5 the page.  I'm not sure what to do... this seems to be really bizarre and unproductive behavior.

If someone can help me out, I would be very grateful.

Thanks for your time,
Michael