Skip to content

Instantly share code, notes, and snippets.

@jboesch
Created April 7, 2011 20:18
Show Gist options
  • Save jboesch/908624 to your computer and use it in GitHub Desktop.
Save jboesch/908624 to your computer and use it in GitHub Desktop.
jQuery's complete is not being called when I have 400 headers set... weird.
/*
* So it seems my "complete" callback is never called when I have a header of 400 or 404 set. Any ideas?
*/
// My PHP file..
header("Content-Type: application/json");
header('HTTP/1.1 400 Bad Request');
$response = array(
'status' => 'error',
'message' => 'You need to set the $response var.'
);
echo json_encode($response); // produces valid JSON: {"status":"error","message":"You need to set the $response var."}
// My JS
$.ajax({
url: href,
dataType: 'json',
complete: function(){
console.log('this is NEVER called so long as i have a 400 header');
},
success: function(){
console.log('blah')
},
error: function(){
console.log('this is called when my header is 400. this works!')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment