I have this HTML
<section id="login">
<form>
<input type="text" name="username" size="10" placeholder="username" />
<input type="password" name="password" size="10" placeholder="password" />
<input type="submit" name="login" value="Login" />
</form>
</section>
With this $.ajax()
that calls the PHP (sys_login.php).
$(function(login){
$('#login form').submit(function(e){
var uname = $('input[name="username"]').val();
var pwd = $('input[name="password"]').val();
var dataObject = {
command : "login",
username : uname,
password : pwd
};
$.ajax({
type : "POST",
url : "application/sys/sys_login.php",
data : dataObject,
dataType : "json",
success: function(response, status){
if (response.status===true){
docCookies.setItem("sessionid", response.sessionid);
docCookies.setItem("username", response.username);
docCookies.setItem("roles", response.roles);
location.href = "application/index.php";
}else{
console.log("false")
}
},
beforeSend:function(){
console.log("sending")
}
}).error(function() {
console.log("error");
});
e.preventDefault();
});
});
But it never got to the sys_login.php
file. If I use GET
, it will reach the php file. During debug, even the console didn't print anything. What did I do wrong?
**UPDATE Apparently the backend server malfunctioned. The script works on other machines. Thank you for you time guys.