Reputation: 15
I am using Jquery ajax to send data to to the server. It is working well in chrome but not in my IE and firefox.
function login()
{
var username=$('#username').val();
var password=$('#password').val();
if(username=="" || password=="" )
{
alert("Please fill all the required fields");
}
else
{
$.ajax({
type: "POST",
url: "../users/login",
async: false,
data: 'username='+ username + '&password='+ password,
success : function(data) {
//alert(data);
if(data=="1")
{
//alert("Successfull");
window.location = "<?php echo $this->Html->url(array('controller' => 'users', 'action' => 'uhome')); ?>";
}
else
{
alert("Invalid login credentials. Please check again.");
}
}
});
}
}
Every alert before $.ajax
is working. But not anything with ajax
in Firefox and IE
. Working well in chrome
. Please advice me a solution.
Upvotes: 0
Views: 1076
Reputation: 15404
data should be a javascript object, like this:
data: {'username': username, 'password': password}
Upvotes: 1
Reputation: 2759
As far as I can tell, the way data is passed it's handled differently in different browsers (Please correct me if it isn't the case). You better correct that part as following
var postData = {};
postData.username = username;
postData.password = password;
$.ajax({
type: "POST",
url: "../users/login",
async: false,
data: postData,
success : function(data) { // You callback function}
});
Upvotes: 1