Jump to content

Simple AJAX function causing difficult debug in chrome/safari


Derleek

Recommended Posts

Hi,

 

I have a *very* simple jQuery/ajax script for a membership driven website.  The script just checks to see if the user entered info, validates it against my database and returns 1 for a failed login attempt, and 0 if the username/password match.

 

 

The function works perfectly when I run it w/o calling it from ajax. 

 

**Firefox:** everything works. 

**Chrome/Safari:** The query is locking everything up.  When I enter valid info, there isn't even any record of a request going out (in the developer tools chrome/safari supply).  When invalid info is entered the request is going out and it returns 3.

 

I'm pretty baffled by this.

 

Is it a "sandbox" issue?  as I understand it Firefox and Chrome/safari handle XHR differently... Although don't ask me how.

 

I am running a base install of MAMP.  Could this be something on my developer environment?  (I will be testing it on a live server later this afternoon)

 

Here is my AJAX call and the php script it is calling.

 

AJAX:

 

   

$.ajax({
      //I've also tried..
      //url: '_modules/php/session.php',
     url: 'http://localhost/current/100TradeJack/httpdocs/_modules/php/session.php',
     type: 'POST',
     cache: false,
     timeout: 5000,
     data: "method=login&"+$('#loginTop').serialize(),
     error: function(XMLHttpRequest, ajaxOptions, thrownError)
     {
      alert("ERORR!!");
     },
     success: function(response){
      alert(response);
      if(response == '0'){ 
       alert("log user in");
       window.location.replace("http://localhost/current/100TradeJack/httpdocs/trading.php");
      } else if(response == '1') {
       alert("invalid username/password");
      } else {
       alert("ERRROOR!");
      }
      
     }
    });

 

session.php:

 

   

$connection = mysql_connect("localhost","root","root") or die(mysql_error());
    mysql_select_db("sandbox_members", $connection) or die(mysql_error());
    
    
    if($email){
     $email = mysql_real_escape_string($email);
    } else {
     return 1;
    }
    
    if($password){
     $password = mysql_real_escape_string($password);
    } else {
     return 1;
    }
    
     
    $query = "SELECT * FROM users WHERE username='". $email . "' AND password='". $password ."'";
    
    $result = mysql_query($query);
    
    if($row = mysql_fetch_array($result)){
     return 0; 
    } else {
     return 3;
    }
    
    //if it gets to here the username/password combo was incorrect or was not found in the db
    return 1;
    mysql_close($connection);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.