I just started working with jQuery and love it. However, I have a problem with ajax call, and I was wondering if anyone could help me. Here is my ajax call:
//start the ajax $.ajax({ //this is the php file that processes the data and send mail url: "php/login.php", //GET method is used type: "GET", //pass the data data: data, //Do not cache the page //cache: false, //success success: function (html) { //if process.php returned 1/true (send mail success) if (html==1) { //hide the form alert( html ); $('.form').fadeOut('slow'); //show the success message $('.done').fadeIn('slow'); //if process.php returned 0/false (send mail failed) } else alert('Sorry, unexpected error. Please try again later.' + html); }, error:function (xhr, ajaxOptions, thrownError, request, error){ alert('xrs.status = ' + xhr.status + '\n' + 'thrown error = ' + thrownError + '\n' + 'xhr.statusText = ' + xhr.statusText + '\n' + 'request = ' + request + '\n' + 'error = ' + error); } });
and here is my conclusion:
xrs.status = 200
throw error = undefined
xhr.statusText = OK
request = undefined
error = undefined
my php looks like this:
<?php //turn on error reporting, set header ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); header('Content-Type: text/xml'); //pull variables //Need to do some error checking here $username = $_GET['name']; $password = $_GET['pass']; //connect with database $con = mysql_connect("localhost","root",""); //if connection unsuccessful if(!$con){ //stop, and display error die('Could not connect: ' . mysql_error()); } mysql_select_db("musicneverstopped", $con); //end connecting to database //query database for user-submitted username and store result in $result $result = mysql_query("SELECT * FROM users WHERE username = '$username'"); //if no results returned if(!$result){ //stop and display error die(mysql_error()); } //check if a single result was returned if(mysql_num_rows($result) == 1){ //if true, set the returned results to $row $row = mysql_fetch_array($result); //check if password from user matches password from database if($password == $row['password']){ //if true, begin session session_start(); //assign session variables $_SESSION['username'] = $row['username']; $_SESSION['privilege'] = $row['privlege']; //send user to index page //header('Location: http://localhost/musicneverstopped'); mysql_close($con);//close mysql connection return 1; } else{ mysql_close($con);//close mysql connection //if false, send user to login page return 0; } mysql_close($con); }//end if(mysql_num_rows($result) == 1) else{ mysql_close($con);//close mysql connection return 0; } ?>
I know that this is not product quality, but it looks like it should work ...
Does anyone see why the error function is triggered? All help is appreciated. Thank you in advance. Dan
source share