0

In the following code I'm getting 'TypeError: response is null' in Firebug. I've tried many combinations and ways of trying to get the response but with no success. Please have a look and tell me what I'm doing wrong. Thanks!

$("a.logmein").colorbox({ width:"540", height:"420", href:function(){ return this.href + " #login"; }, onComplete: function(){ $("#formLoginUser").submit(function(){ $.ajax({ data: $(this).serialize(), type: "POST", url: $(this).attr('action'), success: function(response) { if(response.status == 'fail'){ $("#notifications").removeClass().addClass('ajaxerror').html(response.message).show(); } else { $("#notifications").removeClass().addClass('ajaxsuccess').html(response.message).show(); } console.log(response); }, error: function (xhr, textStatus, errorThrown) { $("#notifications").addClass('ajaxsuccess').html(xhr.responseText).show(); } }); return false; }); }}); 

ajax.php:

header("Content-Type:application/json"); switch($_REQUEST['action']){ case('formLoginUser'): $afm = $_POST['afm']; $password = $_POST['password']; $query_finduser = sprintf("SELECT * FROM clients WHERE clientafm=%s and clientcode=%s and expires>%s", GetSQLValueString($afm, "text"), GetSQLValueString($password, "int"), GetSQLValueString(strtotime('now'), "int")); $finduser = mysql_query($query_finduser, $connection) or die(mysql_error()); $row_finduser = mysql_fetch_assoc($finduser); $totalRows_finduser = mysql_num_rows($finduser); if($totalRows_finduser==0) { echo json_encode(array("status"=>"fail", "message"=>"Login failed. Please retry")); } else { echo json_encode(array("status"=>"success", "message"=>"Login successful!")); } break; default: break; }//switch end 
3
  • 1. Are you sure the action attribute is properly set? (i.e. is it pointing to the right script). 2. Are you sure the script is outputting anything? (which function calls back? Is it success?) in which case are you just not getting into the case('formLoginUser') bit? You might have a problem if using $_REQUEST be sure not to overwrite post variables with get variables (or cookies). Similarly not all server setups allow you to use $_REQUEST. Is there a working example we can see? Commented Sep 3, 2012 at 12:28
  • The action is set properly, it's "includes/ajax.php?action=formLoginUser". In my ajax.php I return a json object in both cases, as you can see in my code. I used $_REQUEST with no problem before trying to make the form submit with ajax so there shouldn't be a problem there either. Unless ajax doesnt get along with $_REQUEST very well. Commented Sep 3, 2012 at 12:35
  • Hmm so it all works without ajax? Are there any javascript errors? Does the success function call back? (add alert('called success'); to the start of the callback function) Commented Sep 3, 2012 at 12:59

1 Answer 1

1

Due jQuery docs success callback function has 3 input parameters: success(data, textStatus, jqXHR). What about the rest of parameters? Try to inspect them. Maybe error is in there.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.