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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:59:23+00:00 2026-05-11T16:59:23+00:00

I have an application that uses Ajax.Request and its onSuccess event handler in lots

  • 0

I have an application that uses Ajax.Request and its onSuccess event handler in lots of places.

I need to call a function (that will check the response) before all these onSuccess events fire. I tried using Ajax.Responders.register with onComplete event but it fires after Ajax.Request‘s onSuccess event. Any suggestions?

  • 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-11T16:59:23+00:00Added an answer on May 11, 2026 at 4:59 pm

    This might be a little late, but for the benefit of anyone else wondering about the same problem I will propose this solution:

    You can use Prototypes own implementation of aspect-oriented programming to do this. Granted you will have to modify all your onSuccess-parameters, but it can be done with a simple search-and-replace, instead of updating all your callback functions. Here is an example Ajax.Request creation:

    new Ajax.Request('example.html', {
        parameters: {action: 'update'},
        onSuccess: this.updateSuccessful
    });
    

    Say you have similar code snippets spread all over your code, and you want to preceed them all with a certain function that validates the response before the actual function is run(or even prevented from running at all). By using Funtion.wrap supplied in Prototype we can do this by extending the code above:

    new Ajax.Request('example.html', {
        parameters: {action: 'update'},
        onSuccess: this.updateSuccessful.wrap(validateResponse)
    });
    

    Where ‘validateResponse’ is a function similar to this:

    // If you use the X-JSON-header of the response for JSON, add the third param
    function validateResponse(originalFn, transport /*, json */) {
        // Validate the transport
    
        if (someConditionMet) {
            originalFn(transport /*, json */);
        }
    }
    

    Thus you have extended your onSuccess-functions in one central place with just a quick search for onSuccess and pasting in ‘wrap(validateResponse)’. This also gives you the option of having several wrapper-functions depending on the needs of the particular Ajax-request.

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer DataTables are definitely much heavier than Lists, both in memory… May 11, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer A decorator seems a better option to me. I am… May 11, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer The current version has improved support for tab order, so… May 11, 2026 at 7:59 pm

Related Questions

I have written a web app in PHP which makes use of Ajax requests
I have a problem. I built a script to make a request to an
Here is my current question: I'm guessing that my problem (described below) is being
I'm about to start a fairly Ajax heavy feature in my company's application. What
I have an ASP.NET MVC (using the release candidate) application that works with a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.