title: Phonegap app communicate with php server without using ip address
body: <p>Question:
  How can I get a phonegap application (using ajax) to communicate with a php server inside a local network without knowing the server's IP address?  </p>
  
  <p>I tried using the hostname as the URL (<a href="http://hostname/" rel="nofollow">http://hostname/</a>) and it works on my computer's browser but it doesn't work on android or in my application.  </p>
  
  <p>Right now, the server has a static IP address but I would like for the application to work with a server that has a dynamic IP address instead.  </p>
  
  <p>I came across a couple of questions on here that were similar except they required connecting to an external server (<a href="http://jsonip.appspot.com/" rel="nofollow">http://jsonip.appspot.com/</a>) and they returned the IP address given by the service provider.  I am looking for something to run in a local network to give the IP address assigned by the router.</p>
  
  <p>The only other thing I could think of was sending a UDP broadcast which, from what I've read, is hard to do if not impossible.</p>
  
  <p>Would anyone be able to provide some more input or options?</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <pre><code>$.ajax({
      type: "POST",
      dataType: "JSON",
      url: "http://home-server/application.php",
      data: {username: $("#username").val(), password: $("password").val()}
      success: function(data) {
          if (data == "approved") {
              //redirect user to home page
          } else if (data == "invalid") {
              //clear form
          }
      },
      error: function(x, exception) {
          alert("Error");
      }
  });
  </code></pre>
  
  <p>The url works on my computer but android/phonegap can't resolve the url. I read up on the access element and my understanding of it led me to try the following  without luck:</p>
  
  <pre><code>&lt;access origin="http://home-server/" /&gt;
  &lt;access origin="http://home-server/application.php" /&gt;
  &lt;access origin="*" /&gt;
  </code></pre>