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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.