Note that there are some explanatory texts on larger screens.

plurals
  1. POFailing jQuery ajax call
    text
    copied!<p>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:</p> <pre><code>//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); } }); </code></pre> <p>and here's my output:</p> <p>xrs.status = 200<br> thrown error = undefined<br> xhr.statusText = OK<br> request = undefined<br> error = undefined </p> <p>my php looks like:</p> <pre><code>&lt;?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; } ?&gt; </code></pre> <p>I know it's not production quality, but it looks like it should work...</p> <p>Anyone see why the error function is firing? All help is appreciated. Thanks in advance. Dan</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload