I was trying to make a Phonegap App which has a simple login form, which should ideally connect to a PHP form, and retrieve the user role.
I would like to clarify following things:
- My Login Page, written in PHP works fine.
-
When given the proper credentials as Get parameters, it returns the right JSON tags :
{"update":true,"msg":"","role":"admin"}
Here is my Phonegap App HTML code. Kindly assist me on where I am going wrong. Assume that the username is username and password is password.
<!DOCTYPE html>
<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" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<form>
<input id="username" name="username"placeholder="Email"></input>
<input id="password" name="password"type="password" placeholder="Password"></input>
<input type="button" value="Login" id="btnLogin"/>
</form>
<div id="myDate"></div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function()
{
$("#btnLogin").click(function()
{
$( "#myDate" ).text( "Reached Here" );
$.ajax({
url:"https://myurl.com/api-file.php",
type:"GET",
dataType:"json",
data:{username:"username",password:"password"},
ContentType:"application/json",
success:function(response)
{
alert(JSON.stringify(response));
},
error: function(error)
{
alert(JSON.stringify(error));
}
})
});
});
</script>
</body>
</html>
How the App should perform is, when I click the button, it calls the jquery code, which generates an AJAx request to the php file and retrieves a JSON string, which I intend to only pop as alert, as of now.
However, clicking the button does absolutely nothing.
I am hardcoding the username and password now but can and will take it from fields later on. Need to test this first before I do that though. Kindly assist on where am I going wrong.