Redirect to an application page Not on the same server after login

Redirect to an application page Not on the same server after login

I have a HTML5 app with a log in screen. When I enter the details, it goes out to an external server, runs a php file called login.php and check the details.

If the details are correct I need it to redirect back to the HTML5 app to the page with id #home on the index.html file. 

If the index.html and login.php are both sitting together on the server, a header method going to work fine. But now, the html file is resting on a mobile phone as a HTML5 app, which reaches out to the server (which is possible - I have the server url). Checks for credentials and redirects. How is it going to redirect back to my app on the phone? There is no URL for the app on the phone.

From my understanding, I need to use Ajax for this purpose. I Attempted with Ajax too but nothing happens. Please advice. I attached my ajax code below too.   


**First page on the app where you enter log in details:** 

  1.     <html>
  2.         <head>
  3.             <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
  4.             <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  5.             <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  6.             <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  7.             <script src="scripts.js"></script>
  8.             <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
  9.         </head>
  10.             <body>
  11.                 <div data-role="page" id="loginForm">
  12.                     <form id="form1" name="form1" method="POST" action="http://www.examplewebsite.com/login.php">
  13.                         <input type="text" name="user" id="user" placeholder="Username"/>
  14.         
  15.                         <input type="password" name="pass" id="pass" placeholder="Password" />
  16.         
  17.                         <input type="submit" name="submit" value="Login" />
  18.                     </form>
  19.                 </div>
  20.                 <div data-role="page" id="home">
  21.                     <h1>Logged In</h1>
  22.                 </div>
  23.             </body>
  24.         </html> 

**Script to check Log in. This php file rests on the server side.**

  1.     //DB Log in credentials
  2. $hostName = 'localhost';
  3. $dbUser = 'fakeuser';
  4. $dbPass = 'fakepass';
  5. $dbName = 'fakedb';
  6. $userTable = "faketable";

  7. //Connect to DB
  8. $conn = mysql_connect($hostName, $dbUser, $dbPass) or die("not connecting");
  9. $dbSelect = mysql_select_db($dbName) or die("no db found");

  10. //Obtain input username and password from the client
  11. $username = $_POST["user"];
  12. $password = $_POST["pass"];

  13. //Check for MySql Injections
  14. if(ctype_alnum($username) && ctype_alnum($password)){
  15. $query1 = mysql_query("SELECT * FROM $userTable WHERE username='$username'");
  16. //query will return 1 if the username exists in the database
  17. $numrows = mysql_num_rows($query1);

  18. if($numrows == 1){
  19. //checking if the password matches the username now
  20. $query2 = "SELECT password FROM $userTable WHERE username='$username'";
  21. $result2 = mysql_query($query2);
  22. $row = mysql_fetch_array($result2, MYSQL_ASSOC);
  23. $pass = $row['password'];

  24. if($password == $pass){
  25. //If successful, redirect to the #home page
  26.                 //anything I can do here to redirect back to #home on my app?
  27. }
  28. else
  29. echo "Password incorrect";
  30. }
  31. else
  32. echo "username incorrect" . $numrows;
  33. }
  34. else{
  35. echo "Not alpha Numeric Input!!";
  36. }

**Attempted Ajax portion**

  1.     var isLogged = false;
  2.     /**
  3.      * Method used to log into the application
  4.      */
  5.     $(document).on("pageinit", "#loginForm", function () {
  6.         $("#form1").on("submit", function (event) {
  7.             event.preventDefault();
  8.             $.ajax({
  9.                 type: "GET",
  10.                 url: "http://www.examplewebsite.com/login.php",
  11.                 data: $("#form1").serialize(),
  12.                 success: function (data) {
  13.                     console.log(data);
  14.                     if (data.loggedIn) {
  15.                         isLogged = true;
  16.                         $.mobile.changePage("#home");
  17.                     } else {
  18.                         alert("You entered the wrong username or password. Please try again.");
  19.                     }
  20.                 }
  21.             });
  22.         });
  23.     });