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 7610005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:18:52+00:00 2026-05-31T01:18:52+00:00

A brainteaser for you. I’ve written this generic JS function. Our system does all

  • 0

A brainteaser for you.

I’ve written this generic JS function. Our system does all of the business logic through AJAX and I’m consolidating the code into a single function so I don’t have to update or maintain 3million+ identical copies of the code across the codebase.

doRequest = function (data,msgBoxElem,origin) {
$.ajax({
  type: "POST",
  url: window.dispatcher_addr,
  data: data,
  dataType: "xml",
  contentType: "text/xml",
  processData: false,      
  success: function(xml) {
    $(msgBoxElem).html(xml.documentElement.getAttribute("msg"));
    location.reload();
  },
  error:function (xhr, ajaxOptions, thrownError){ if (thrownError != 200) {
    var Data = new Array();
    Data["errorcode"]       = xhr.status;
    Data["errortext"]       = thrownError;
    Data["calling_script"]  = origin;
    $.ajax({
      type: "POST",
      url: window.dispatcher_addr,
      data: CreatePayLoad('jslogerror',Data),
      dataType: "xml"        
    });
    }      
  }       

});
}

Now, some of the pages have specific logic that executes in the success, error, and complete handlers for $.ajax(). What I want to know is that if it’s possible to pass in an argument to $.ajax() and then it will execute the custom handler.

Thanks a lot.

Midiane.

  • 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-31T01:18:54+00:00Added an answer on May 31, 2026 at 1:18 am

    You can just add one or more callback arguments to your function like this that will either replace your default handlers or execute in addition to them (your choice how you implement it). Here’s an example of an fnSuccess callback that executes in addition to the default behavior you’ve defined:

    doRequest = function (data,msgBoxElem,origin,fnSuccess) {
        $.ajax({
          type: "POST",
          url: window.dispatcher_addr,
          data: data,
          dataType: "xml",
          contentType: "text/xml",
          processData: false,      
          success: function(xml) {
            $(msgBoxElem).html(xml.documentElement.getAttribute("msg"));
            fnSuccess();
            location.reload();
          },
          error:function (xhr, ajaxOptions, thrownError){ if (thrownError != 200) {
            var Data = new Array();
            Data["errorcode"]       = xhr.status;
            Data["errortext"]       = thrownError;
            Data["calling_script"]  = origin;
            $.ajax({
              type: "POST",
              url: window.dispatcher_addr,
              data: CreatePayLoad('jslogerror',Data),
              dataType: "xml"        
            });
            }      
          }       
        }); 
    }
    

    Or, if you wanted the caller’s code to execute instead of your default implementation, you could do it like this:

    doRequest = function (data,msgBoxElem,origin,fnSuccess) {
        $.ajax({
          type: "POST",
          url: window.dispatcher_addr,
          data: data,
          dataType: "xml",
          contentType: "text/xml",
          processData: false,      
          success: function(xml) {
              if (fnSuccess) {
                  fnSuccess(xml);
              } else {
                  $(msgBoxElem).html(xml.documentElement.getAttribute("msg"));
                  location.reload();
              }
          },
          error:function (xhr, ajaxOptions, thrownError){ if (thrownError != 200) {
            var Data = new Array();
            Data["errorcode"]       = xhr.status;
            Data["errortext"]       = thrownError;
            Data["calling_script"]  = origin;
            $.ajax({
              type: "POST",
              url: window.dispatcher_addr,
              data: CreatePayLoad('jslogerror',Data),
              dataType: "xml"        
            });
            }      
          }       
        }); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of a brainteaser question, since the code works perfectly fine as-is,
another brain teaser. This isn't the usual but Apostrophes are breaking my Queries as
I was going through C# Brainteasers ( http://www.yoda.arachsys.com/csharp/teasers.html ) and came across one question:
For my algorithm design class homework came this brain teaser: Given a list of
Looking on the internet for C++ brainteasers, I found this example: #include <iostream> using
This is more of a brain teaser for me as the linqTOsql query is
Someone asked me a brainteaser, and I don't know; my knowledge slows down after
I have already asked a question about this, but the problems keeps on hitting
My Brain Is Going to Explode.. . I have five images all named 0,1,2,3,4.
I have a brain-teaser for all you SQL Server 2008 Reporting gurus out there

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.