Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:13:33+00:00 2026-05-28T20:13:33+00:00

Possible Duplicate: jQuery ajax error function I am trying to replace a global ajax

  • 0

Possible Duplicate:
jQuery ajax error function

I am trying to replace a “global” ajax error handler with a function that I can call from each ajax call due to problems observed in our implementation.

$(document).ajaxError(function(e, jqXHR, settings, exception) {
    // using BrowserDetect function to get browser info
    var browser    = BrowserDetect.browser;
    var browserVer = BrowserDetect.version;
    var browserOS  = BrowserDetect.OS;
    var ajax_url   = settings.url;
    $.ajax({async: true, 
            type:     'POST',
            url:      AJAX_ERROR_LOG_URL, 
            dataType: 'json',
            data:     'host='myhost.com&status='+jqXHR.status+'&error='+jqXHR.responseText+'&expmessage='+exception.message+'&url=' 
                       +ajax_url+'&browser='+browser+'&browserVer='+browserVer+'&browserOS='+browserOS
    });
    if (jqXHR.status === 0) {
        final_message(ERROR_MSG + '0'); // Not connected. Please verify network is connected.
    } else if (jqXHR.status == 404) {
        final_message(ERROR_MSG + '404'); // Requested page not found. [404]
    } else if (jqXHR.status == 500) {
        final_message(ERROR_MSG + '500'); // Internal Server Error [500].
    } else if (exception === 'parsererror') {
        final_message(ERROR_MSG + '1'); // Requested JSON parse failed.
    } else if (exception === 'timeout') {
        final_message(ERROR_MSG + '2'); // Time out error.
    } else if (exception === 'abort') {
        final_message(ERROR_MSG + '3'); // Ajax request aborted.
    } else {
      if(browserVer == '7' && browser == 'Explorer') {
        final_message(ERROR_MSG + '100'); // Uncaught Error
      } else {
        final_message(ERROR_MSG + '99'); // Uncaught Error
      }
    }
});

I want to convert this to a function and call it like this:

$.ajax({async: true, 
        type:'POST',
        url: url, 
        dataType: 'json', 
        data:     "username="+username+"&password="+pass,
        success:  ajaxLoginResult
        error:    logAjaxError(jqXHR, textStatus, errorThrown)
});

function logAjaxError(jqXHR, textStatus, errorThrown) {
  // more code here to log the error
}

The problem lies in the fact that I cannot get the url of the ajax callpassed to the error callback as the only things that are passed is the jqXHR, textStatus, errorThrown. In the .ajaxError setup, the settings is passed and that is where we get the url from.
Any ideas?

Edited 2/3:
Here is the Add_Course function for you to see:

function Add_Course(reason) {
  var eventid = $('#eventid'+$('#obleventcode').attr('value')).val();
  var url = AJAX_URL_ADDTOCART + '?sku='+eventid+'&mainitem=true&pid='+pid;
  if(reason != 'VOUCHER'){
    log_url(url);
    $.ajax({async: true, 
            type:'POST',
            url: url, 
            dataType: 'json', 
            success: function(data){
              if(data.result=='success') {
                var cemsg_index=reason.indexOf('CEMSG');
                if(cemsg_index>=0) {
                  final_ce_message(reason.substr(cemsg_index+6));
                } // if(cemsg_index>=0)
              } else {
                $('#sm_content .oblcontent').html(data.message);
              } // if(data.result=='success')
            },
            complete: function(jqXHR, textStatus) {
              log_url('redirecting to cart');
              window.location = CART_URL;
            } // complete
    });
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:13:34+00:00Added an answer on May 28, 2026 at 8:13 pm

    First, congratulations on actually checking for errors. So many people write code that never expect things to go wrong on the internets. Ha.

    Rather than editing every call to $.ajax you can call $.ajaxSetup() to have every call use your function for an error handler. The error handler signature is error(jqXHR, textStatus, errorThrown) which conveniently matches your function, so try a call to $.ajaxSetup({ error: logAjaxError }) before you do any $.ajax calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: using jquery $.ajax to call a PHP function I need to call
Possible Duplicate: jQuery: How to stop AJAX function escaping JSON string used to POST
Possible Duplicate: jquery validate & ajax.beginform I'm trying to use the jQuery validate plugin
Possible Duplicate: jquery ajax call taking too long or something for some reason this
Possible Duplicate: Show Page Loading Spinner on Ajax Call in jQuery Mobile Is it
Possible Duplicate: Passing JavaScript Array To PHP Through JQuery $.ajax I'm trying to pass
Possible Duplicate: how to protect ajaxRequest.open php script im making a ajax call from
Possible Duplicate: jQuery Ajax always returns “undefined”? I'm trying to come up with a
Possible Duplicate: Multiple ajax calls inside a each() function.. then do something once ALL
Possible Duplicate: Resetting a multi-stage form with jQuery Once the form submitted, response from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.