10/16/2015 - 11:39 AM

Ajax Error

// You just need to setup your global error handler (.ajaxError) to receive a few of the parameters that jQuery can provide to it:

$(document).ajaxError(function(evt, xhr, settings) {
  if (settings.suppressErrors) {

// After this, you can add suppressErrors: true to the settings of any AJAX request you make, and if it fails the error handler will return without doing what it normally does.

var options  = {type: "POST", url : "/ajax/request-path/", suppressErrors: true};

// For the drupal ajax you should rewrite default error method:

Drupal.ajax.prototype.error = function (response, uri) {
  if (!this.options.suppressErrors) {
    alert(Drupal.ajaxError(response, uri));
  // ... see the all code in drupal.js

// Call the drupal ajax

var settings = {url : "/ajax/request-path/" + Drupal.settings.uid};
var ajax = new Drupal.ajax(false, false, settings);
ajax.options.suppressErrors = true;
ajax.eventResponse(ajax, {});

// To check errors you need to provoke an ajax error forcibly
// To do this you should put this code into the ajax callback function. 

header('HTTP/1.1 500 Internal Server Booboo');
header('Content-Type: application/json; charset=UTF-8');
die(json_encode(array('message' => 'ERROR', 'code' => 1337)));