I'm trying to get userconnexion in Ajax (will be used in Phonegap application).
I've no javascript error but my ajax function is always with error status without details.
This is my form :
<form id="loginForm">
<div data-role="fieldcontain" class="ui-hide-label">
<label for="username">Username:</label>
<input type="text" name="username" id="user"/>
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="password">Password:</label>
<input type="password" name="password" id="pass"/>
</div>
<input type="text" size="25" id="message" value="error" />
<input type="button" value="Submit" id="sendButton"/>
</form>
This is my Js file
$(document).ready(function(){
$(window).load(function(){
$('#sendButton').click(function() {
var user = $("#user").val();
var pass = $("#pass").val();
$.ajax({
url: "http://myurl.php",
type: "GET",
data: { username: user, password: pass },
success: function (html) {alert(html); },
error: function(){alert('false');}
});
});
});
});
This is my php file
<?php
$user = $_GET['username'];
$pass = $_GET['password'];
$link = mysql_connect('dbhost', 'dblogin', 'dbpss');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('dbname',$link);
$result = mysql_query("SELECT email, mdp, id FROM auteur WHERE email = '$user'");
while($row = mysql_fetch_array($result)){
if(md5($pass) == $row["mdp"]){
echo $row["id"];
} else {
echo '';
}
}
?>
About my PHP I've try http://myurl.php?password=test&username=test and I get my ID, so I think this part works.
But when I try form with same value, I get a 'false', so an error...
I'm a newbie, someone can explain me my errors ?
Thanks a lot !