I am new in web-technology. I am tring to send data from PHP Server to client test.html. But only alert("1") comes but alert("2") does not printed I just wanted to print Json data into alert(JSON.stringify(response));, Please tell me where I am wrong?
My server code is api.php
<?php
header('Access-Control-Allow-Origin: *');//Should work in Cross Domaim ajax Calling request
mysql_connect("localhost","root","1234");
mysql_select_db("demo");
if(isset($_GET['type']))
{
if($_GET['type']=="login"){
$username=$_GET['UserName'];
$Password=$_GET['Password'];
$query="Select * from registration where UserName='$username' and Password='$Password'";
$result=mysql_query($query);
$totalRows=mysql_num_rows($result);
if($totalRows>0){
$recipes=array();
while($recipe=mysql_fetch_array($result, MYSQL_ASSOC)){
$recipes[]=array('User'=>$recipe);
}
$output=json_encode(array('Users'=>$recipes));
echo $output;
}
}
}
else{
echo "Invalid format";
}
My Client code test.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JSON </title>
<script src="Scripts/jquery-1.8.2.js">
</script>
<script>
$(document).ready(function(){
alert("1");
$("#btnLogin").click(function(){
alert("2");
$.ajax({
url:"http://localhost/Experiements/webservices/api.php",
type:"GET",
dataType:"json",
data:{type:"login", UserName:"abhishek",Password:"123456"},
ContentType:"application/json",
success: function(response){
alert(JSON.stringify(response));
},
error: function(err){
alert(JSON.stringify(err));
}
})
});
});
</script>
</head>
<body>
<input type="button" id="btnLogin" name="btnLogin" value="Login"/>
</body>
</html>
DataBase is demo, username is root and password is 1234 and table is registration