Failing jQuery ajax call

ajax, jquery

Solution

Perhaps you could add the `dataType` parameter (passing "text" as the datatype) to your .ajax call... I usually get a `parsererror` when getting back malformed XML or JSON. When you don't set the `dataType`, jquery tries to automatically determine if the response is XML or HTML. Perhaps this is failing, since your response is neither? See http://docs.jquery.com/Ajax/jQuery.ajax#options

Problem

I've just started working with jQuery and love it. I'm having a problem with an ajax call though, and I was wondering if anyone could help me out. Here's 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's my output: xrs.status = 200 thrown error = undefined xhr.statusText = OK request = undefined error = undefined my php looks like: ``` <?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 it's not production quality, but it looks like it should work... Anyone see why the error function is firing? All help is appreciated. Thanks in advance. Dan

Original source