title: Basic POST with JQuery Mobile from form using php
body: <p>Firstly I apologize for posting another one of these questions, but I've dove through a ton of SO questions related to this topic and haven't be able to figure out my problem. I'm new to PHP and an amature at best using Jquery mobile and the like.</p>
  
  <p>I'm attempting to post to a .php file and get a response back. Eventually this will evolve into a database posting yada yada. For now, I can't seem to get my response back from my post. I'm running Xampp to host the php, Jquery Mobile is being used in other functions so it does work properly, </p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form&gt;
          &lt;p&gt;Username: &lt;/p&gt;&lt;input type="text" id="username" value="" /&gt;
          &lt;p&gt;Password: &lt;/p&gt;&lt;input type="text" id="password" value="" /&gt;
          &lt;input type="button" onclick="submitLogIn()" value="Log In" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>function submitLogIn() {
  
      alert("Submitting: " + $('#username').val() + $('#password').val());
      var dbURL = "http://localhost/testerpage.php";
  
      $.post(dbURL, {
          //These are the names of the form values
          Username: $('#username').val(),
          Password: $('#password').val()
  
      }, function (data,status) {
          alert(status); //Won't fire
          alert(html); //Won't fire
          var response = html;
          alert(response); //Won't fire
          if (response == "Success")
          {
              alert("Success!"); //Won't fire
              //testlog.innerHTML = "Success";
          }
          else
          {
              alert("Failure!");//Won't fire
              //testlog.innerHTML = "Failure";
          }
  
      });
  
      alert("Finished"); //Fires
  
  };
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  
      // VARS
      $Username=$_GET["Username"]; //Also tried _POST
      $Password=$_GET["Password"]; //Also tried _POST
  
      //VALIDATION
      if(
      $Username=="" ||
      $Password==""
      ) {
          echo "Error";
      } else {
          echo "Success";
      }
  ?&gt;
  </code></pre>
  
  <p>My best guess is that something is wrong with the .php because all of the questions I've looked at seem to confirm my JavaScript is right. All of my alerts fire except the ones in the call back function. The username and password are also correctly being set so that isn't the problem. I tried using _POST and _GET in my .php, I originally was using _POST because I was posting data but I was following this question: (<a href="https://stackoverflow.com/questions/12597891/phonegap-contact-form-not-working-over-php?rq=1">Phonegap contact form not working over PHP</a>) and it did the opposite so I changed it. No difference. My .php is actually hosted for sure (I can navigate to it without an error). I also tried using the $.ajax function but had the same issues.</p>
  
  <p>Thanks in advance. </p>
  
  <p><strong>EDIT:</strong> Added more of the HTML (all that should be relevant) per request, can't add it all as it is too long.</p>
  
  <pre><code>    &lt;html&gt;
          &lt;head&gt;
              &lt;meta charset="utf-8" /&gt;
              &lt;meta name="format-detection" content="telephone=no" /&gt;
              &lt;meta name="msapplication-tap-highlight" content="no" /&gt;
              &lt;!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 --&gt;
              &lt;meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /&gt;
  
              &lt;!-- Stylesheets --&gt;
              &lt;link rel="stylesheet" href="css/snctfy2/snctfy2.css" /&gt;
              &lt;link rel="stylesheet" href="css/snctfy2/jquery.mobile.icons.min.css" /&gt;
  
              &lt;link rel="stylesheet" type="text/css" href="css/index.css" /&gt;
              &lt;link href="jquerymobile/jquery.mobile.structure-1.4.2.min.css" rel="stylesheet" type="text/css" /&gt; &lt;!-- Add .structure after theme--&gt;
  
              &lt;!-- Jquery core --&gt;
              &lt;script src="js/jquery.js" type="text/javascript"&gt;&lt;/script&gt;
  
              &lt;!-- Jquery mobile library file --&gt;
              &lt;script src="jquerymobile/jquery.mobile-1.4.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  
              &lt;!-- DateBox --&gt;
              &lt;link rel="stylesheet" type="text/css" href="css/jqm-datebox.css" /&gt;
              &lt;script type="text/javascript" src="js/datebox/jqm-datebox.core.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" src="js/datebox/jqm-datebox.mode.calbox.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" src="js/datebox/jqm-datebox.mode.datebox.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" src="js/datebox/jquery.mobile.datebox.i18n.en_US.utf8.js"&gt;&lt;/script&gt;
  
  
              &lt;!-- Scripts (pre-load)--&gt;
              &lt;script src="js/scripts.js" type="text/javascript"&gt;&lt;/script&gt;
  
              &lt;!-- CSS Override --&gt;
              &lt;link rel="stylesheet" type="text/css" href="css/override.css" /&gt;
  
              &lt;title&gt;SNCTFY&lt;/title&gt;
          &lt;/head&gt;
          &lt;body&gt;
  
      &lt;!--there is some more &lt;div&gt; tags here unrelated--&gt;
          &lt;!--------------------------------------------------------Login Page---------------------
  
  --------------------------------------------&gt;
              &lt;div data-role="page" id="login" data-theme="a" class="bPage"&gt;
                  &lt;div data-role="content"&gt;
                      &lt;form&gt;
                          &lt;p&gt;Username: &lt;/p&gt;&lt;input type="text" id="username" value="" /&gt;
                          &lt;p&gt;Password: &lt;/p&gt;&lt;input type="text" id="password" value="" /&gt;
                          &lt;input type="button" onclick="submitLogIn()" value="Log In" /&gt;
                      &lt;/form&gt;
                      &lt;a href="#register" data-role="button"&gt;Register&lt;/a&gt;
                      &lt;button onclick="showAlert()"&gt;Test&lt;/button&gt;
                      &lt;p id="testlog"&gt;Results&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
      &lt;!-- more &lt;div&gt; pages --&gt;
  
              &lt;!-- Scripts (post-load)--&gt;
              &lt;script type="text/javascript" src="phonegap.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" src="cordova.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript" src="js/index.js"&gt;&lt;/script&gt;
              &lt;script type="text/javascript"&gt;
                  app.initialize();
              &lt;/script&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>EDIT2:</strong> Changed JavaScript to one of the answers to test</p>
  
  <pre><code>function submitLogIn() {
      alert("Submitting: " + $('#username').val() + $('#password').val());
      var username = $('#username').val();
      var password = $('#password').val();
      $.ajax({
          type: "POST",
          url: "http://localhost/testerpage.php", 
          data: { "Username": username, "Password": password },
          success: function (data) {
              if (data) {
  
                  alert(data);
              }
              else {
                  alert('Successfully not posted.');
              }
          }
      });
  
  };
  </code></pre>