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

  • Home
  • SEARCH
  • 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 8366599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:57:16+00:00 2026-06-09T12:57:16+00:00

var _orgAjax = jQuery.ajaxSettings.xhr; jQuery.ajaxSettings.xhr = function () { var xhr = _orgAjax(); DoSomeLogging();

  • 0
var _orgAjax = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function () {
    var xhr = _orgAjax();
    DoSomeLogging();
    return xhr;
};

I’ve inherited the code above. Can someone confirm my understanding that this will override any $.ajax(...) call anywhere else on the page and execute DoSomeLogging() each time?

I’m hunting a different bug but stumbled upon this and wanted to be sure I understand what this piece of legacy code does?

I’m not convinced this is good practice/use of the xhr function anyway but interested to hear your opinions. We’re using Jquery 1.7.1.

Lastly, out of curiosity, what if _orgAjax() failed to return if an (async: false) call, would the logging method even get reached?

Thanks.

  • 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-06-09T12:57:17+00:00Added an answer on June 9, 2026 at 12:57 pm

    Can someone confirm my understanding that this will override any
    $.ajax(…) call anywhere else on the page and execute DoSomeLogging()
    each time?

    Yes. This will define the global default behaviour unless overwritten in a local ajax implementation.

    The more documented way of defining global settings is the use of ajaxSetup().

    However, you are able to set default global behaviour using ajaxSettings as well, though this particular way is not documented anywhere directly in the jQuery documentation.

    See DEMO – With Success

    Lastly, out of curiosity, what if _orgAjax() failed to return if an
    (async: false) call, would the logging method even get reached?

    The settings are configuring the beforeSend so the logging method will always be called regardless of the async setting as pointed out correctly by Esailija.

    See DEMO – with async: true, logging is called before return
    See DEMO – with async: false, logging is also called before return

    However please note though, according to the ajax documentation:

    As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is
    deprecated; you must use the complete/success/error callbacks.

    I know you are using 1.7.1 but if something becomes deprecated there usually is a good reason and I don’t see any harm in preparing for that.

    To configure ajax with logging on complete by default:

    See DEMO – Configuring default logging for complete for document.
    I know that would make your logging being executed after and not before the send but that seems to be the way 1.8 prefers it I think.

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

Sidebar

Related Questions

var conversations = new Array(); jQuery('.CChatWindow').each(function(){ if (jQuery(this).is(:visible) && jQuery(this).attr(data-conversationid) != 0) { alert(jQuery(this).attr(data-conversationid));
var positions = [ 00, 01, 02, 03, 04, 05 ]; jQuery.each( positions, function(players)
var AppPatientsList = JSON.parse(JSON RESPONSE); var AppPatientsListSort = AppPatientsList.sort(function(a,b){ return a.firstName.toLowerCase() <b.firstName.toLowerCase() ? -1
var j$ = jQuery.noConflict(); j$(document).ready(function(){ j$.fn.slideShow = function(timeOut){ var $slidecontainer = this; this.children(':gt(0)').hide(); setInterval(function()
var date = new Date(1257397200000​); document.write(date); ​ Ran the code above I got Wed
var rinlinejQuery = / jQuery\d+=(?:\d+|null)/g, html: function( value ) { if ( value ===
var foo = { p1: function(){ return this.p2; }, p2: function(){ console.log('i am foo.p2');
var coords = {'x' : 982, 'y' : 1002 }; The above code is
var s = Hi; Date.now = function (){ return new Date(); } s.createdOn =
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });

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.