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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:42:21+00:00 2026-05-26T13:42:21+00:00

I am working on a web app using JSF w/Seam. I want to be

  • 0

I am working on a web app using JSF w/Seam. I want to be able to call a JavaScript function after every ajax response. I’m looking for a way to do this without putting an oncomplete attribute on every commandLink/commandButton on every page.

I think there’s a way to set up a servlet filter (interceptor? I get the terms confused) to inject the JS call into each response. I’m going to look into that. In the meantime, if anyone has any other suggestions, I’m all ears.

EDIT: I think the jQuery ajaxSuccess method might be the way to go here, but I’m not sure how to actually use it. I can’t get anything to register. I basically want to add code to get any and all ajax requests from any source to call my JavaScript method on success. Can anyone show me the proper way to do this? I’ve tried a number of ways to do this, including adding jQuery("*").ajaxSuccess(function(){myFunction();}); to the bottom of my template xhtml file.

  • 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-26T13:42:22+00:00Added an answer on May 26, 2026 at 1:42 pm

    Rewritten answer: see original answer in revision history

    You could override the default send method of XMLHttpRequest with one that hijacks the readystatechange handler:

    (function () 
    { 
        var xhrSend = XMLHttpRequest.prototype.send; 
        XMLHttpRequest.prototype.send = function  () 
         { 
            var handler = this.onreadystatechange; 
            this.onreadystatechange = function () 
            { 
                if (handler) {
                    if (handler.handleEvent) handler.handleEvent.apply(xhr, arguments);
                    else handler.apply(xhr, arguments);
                }
                if (this.readyState == 4) 
                { 
                    // your oncomplete function here 
                    this.onreadystatechange = handler; 
                 } 
             }; 
            xhrSend.apply(this, arguments); 
        }; 
    })(); 
    

    Edit: The above function doesn’t work with jQuery requests, and so potentially it could fail with other libraries as well. The revision below addresses the issue with a setTimeout hack to delay the code that overrides the handler. Of course, with jQuery, you can just use the .ajaxSuccess() global handler, but for other libraries with similar behavior, this would be useful.

    (function() {
        function globalHandler() {
            if (this.readyState == 4) {
                // your oncomplete code here
            }
        }
        var xhrSend = XMLHttpRequest.prototype.send;
        XMLHttpRequest.prototype.send = function() {
            var xhr = this;
            if (xhr.addEventListener) {
                xhr.removeEventListener("readystatechange", globalHandler);
                xhr.addEventListener("readystatechange", globalHandler, false);
            }
            else {
                function readyStateChange() {
                    if (handler) {
                        if (handler.handleEvent)
                            handler.handleEvent.apply(xhr, arguments);
                        else
                            handler.apply(xhr, arguments);
                    }
                    globalHandler.apply(xhr, arguments);
                    setReadyStateChange();
                }
                function setReadyStateChange() {
                    setTimeout(function() {
                        if (xhr.onreadystatechange != readyStateChange) {
                            handler = xhr.onreadystatechange;
                            xhr.onreadystatechange = readyStateChange;
                        }
                    }, 1);
                }
                var handler;
                setReadyStateChange();
            }
            xhrSend.apply(xhr, arguments);
        };
    })();
    

    http://jsfiddle.net/gilly3/FuacA/5/
    I tested this in IE7-9, and the latest versions of Chrome and FF

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

Sidebar

Related Questions

I am working on a web app using C# and asp.net I have been
I am currently working on a web app using Wicket and started using jQuery
Im working on an iphone web app using JQTouch , im just wondering what
I am working on an iPhone mobile web app using jqtouch to make it
I'm working on a database for a small web app at my school using
I am currently working on a simple web application through Google App engine using
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
I am working on an iPhone Web App using HTML & CSS. I have
Using Visual Studio 2008 and VB.Net: I have a working web app that uses
Im working in a Web App with Java and JSF. I have a simple

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.