0

I'm trying to send a getJson call from my app (login form) to get an external JSON from PHP file. and there if login and password are ok. My app will redirect from login.html to home.html.

This is my script located in login.html shown below

  <script>
   function testlogin() {  

var login = $('#login').val();  
var password = $('#password').val();  
$.ajax({          
    url: "http://http://10.0.2.2/YasmineMarket.php",          
    data: { login: JSON.stringify(login), password: JSON.stringify(password) },  
    dataType: "jsonp",  
    success: function(json, textstatus) {              
        if (json.d == 'Login Success') {                  
            var url = "acceuil.html";  
            $(location).attr('href', url);  
        }  
        else {  
            alert("Wrong Username or password");  
            var url = "index.html";  
            $(location).attr('href', url);                  
        }  
    },  
    error: function(xmlHttpRequest, textStatus, errorThrown) {  
        if (xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)  
            return;  
        else  
            alert(errorThrown);  
    }  
});  
}
</script>

<!DOCTYPE HTML>

<html >


        <form  id="loginForm" method="GET" >

       <table border="0" align="center">
           <tr><td></td></tr>
       <tr><td align="center"><input type="text" name="login" id="login" /></td></tr>
       <br>
   <tr><td align="center"><input type="password" name="password"  id="password" /></td></tr>
   <tr><td align="center"><input type="submit" value="Connexion" onlick="testlogin();"   class="button"   /></td></tr>
   </table>
   </form>

</body>

halfer
  • 19,824
  • 17
  • 99
  • 186
Amin
  • 111
  • 1
  • 15
  • Could you post the error log also ? bdw is this url correct ?url: "http://http://10.0.2.2/YasmineMarket.php", – Suave Nti Jun 19 '12 at 16:07

1 Answers1

-1

This code is not sufficient to find the actual problem here. But this link might help you to write a server authentication. Please go through my old post about jsonp ajax request to a web server using jquery mobile and phonegap.

halfer
  • 19,824
  • 17
  • 99
  • 186
Akilan
  • 1,707
  • 1
  • 16
  • 30