Problem with Ajax form submit

Problem with Ajax form submit

I have this mobile page I'm working on, and I can't seem to get the ajax call to work properly.  Whenever I click the submit button, it reloads the page, with all the data submitted in the url, as in a get method.  However, this data should be submitted via post, and it's only "posting" data back to this page, instead of the "users.php" page like it should be.  My guess would be is that the "submit" function for this is somehow incorrectly implemented, but I'm at a bit of a loss as to what I've done wrong.


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>jcBook</title>
  7. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
  8. <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  9. <link rel="stylesheet" href="style/swipe-page.css" id="demo-style">
  10. <link rel="stylesheet" href="style/default.css" >
  11. <script>
  12. // Bind to "mobileinit" before you load jquery.mobile.js
  13. // Set the default transition to slide
  14. $(document).on( "mobileinit", function() {
  15. $.mobile.defaultPageTransition = "slide";
  16. });
  17. </script>
  18. <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
  19. <script src="js/swipe-page.js"></script>
  20. </head>
  21. <body>

  22. <div data-role="page" id="appSignUp" class="demo-page ui-responsive-panel" data-dom-cache="false" data-theme="a" >

  23. <div data-role="header" data-theme="a" >
  24. <a href="#nav-menu-panel" data-icon="grid" data-iconpos="notext">Menu</a>
  25. <a href="#nav-login-panel" data-icon="in" data-iconpos="notext">Log In</a>
  26. <h1 id="pageTitle"></h1>
  27. </div><!-- /header -->
  28. <div data-role="content" data-theme="e">
  29. <h3 id="notification"></h3>
  30. <form id="frmSignUp" data-transition="fade" >
  31. <input type="hidden" id="action" name="action" value="addUser" />
  32. <input type="hidden" id="clientKey" name="clientKey" value="web" />

  33. <label for="firstName">First name:</label>
  34. <input type="text" id="firstName" name="firstName" />

  35. <label for="lastName">Last name:</label>
  36. <input type="text" id="lastName" name="lastName" />
  37. <label for="email">Email address:</label>
  38. <input type="text" id="email" name="email" />
  39. <label for="password">Please enter a password (minimum 5 characters):</label>
  40. <input type="password" id="password" name="password" />
  41. <label for="password2">Repeat your password:</label>
  42. <input type="password" id="password2" name="password2" />
  43. <label for="mobileNumber">Your Mobile Number:</label>
  44. <input type="text" id="mobileNumber" name="mobileNumber" />

  45. <label for="passphrase">What is your favorite color:</label>
  46. <input type="text" id="passphrase" name="passphrase" />

  47. <input type="submit" id="submit" name="submit" value="Contine" />
  48. </form>
  49. </div><!-- /content -->

  50. <div data-role="footer" >
  51. </div><!-- /footer -->
  52. <div data-role="panel" data-position="left" data-position-fixed="false" data-display="reveal" id="nav-menu-panel" data-theme="a">
  53. <ul data-role="listview" data-theme="a" data-divider-theme="a" style="margin-top:-16px;" class="nav-search">
  54. <li data-icon="delete" style="background-color:#111;">
  55. <a href="#" data-rel="close">Close menu</a>
  56. </li>
  57. <li data-filtertext="" >
  58. <a href="appOverview.php">Overview</a>
  59. </li>
  60. <li data-filtertext="" >
  61. <a href="appAccounts.php">Accounts</a>
  62. </li>
  63. <li data-filtertext="" >
  64. <a href="appLedgers.php">Ledgers</a>
  65. </li>
  66. <li data-filtertext="" >
  67. <a href="appBills.php">Bills</a>
  68. </li>
  69. <li data-filtertext="" >
  70. <a href="appReports.php">Reports</a>
  71. </li>
  72. </ul>

  73. <!-- panel content goes here -->
  74. </div><!-- /panel -->
  75. <div data-role="panel" data-position="right" data-position-fixed="false" data-display="overlay" id="nav-login-panel" data-theme="e">

  76. <ul data-role="listview" data-theme="a" data-divider-theme="a" style="margin-top:-16px;" class="nav-search">
  77. <li data-icon="delete" style="background-color:#111;">
  78. <a href="#" data-rel="close">Close menu</a>
  79. </li>
  80. <li data-filtertext="" >
  81. <a href="appSignUp.php">Sign Me Up!</a>
  82. </li>
  83. <li data-filtertext="" >
  84. <a href="appSignIn.php">Sign In</a>
  85. </li>
  86. <li data-filtertext="" >
  87. <a href="appSignOut.php">Sign Out</a>
  88. </li>
  89. </ul>

  90. </div><!-- /panel -->
  91. <script src="js/onLoad.js"></script>
  92. <script>
  93. $(function() {
  94. $("#submit").click(function() {

  95. var frmData = $("#frmSignUp").serialize();

  96. $.ajax({
  97. url: "users.php",
  98. type: "post",
  99. dataType: "json",
  100. data: frmData,
  101. success: onSuccess
  102. });
  103. });

  104. function onSuccess(data) {
  105. $("#notification").html(data.error);
  106. }
  107. });
  108. </script>
  109. </div><!-- /page -->
  110. </body>
  111. </html>