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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:50:04+00:00 2026-05-30T15:50:04+00:00

I have a basic greasemonkey script shown below, in which I want to run

  • 0

I have a basic greasemonkey script shown below, in which I want to run some code every time an AJAX request is sent by the website I’m running the script on.

I’m using the ajaxSuccess jQuery handler and it’s not being fired. I suspect this might be because the AJAX requests are being sent with the global flag set to false (see http://docs.jquery.com/Ajax_Events). Is there some better way to achieve this that will work even when global is set to false?

Code:

// ==UserScript==
// @name           MyTestScript
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @namespace      NRA
// @include        http://www.mysamplewebsite.com/view/*
// ==/UserScript==

$(document).ajaxSuccess(function(e, xhr) {
    alert("ajax success hit!");
    // I will do my other handling here
});

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-05-30T15:50:05+00:00Added an answer on May 30, 2026 at 3:50 pm

    The jQuery in your userscript runs in a separate environment from the page’s jQuery.

    You need to intercept the page’s AJAX calls so you can use either (A) unsafeWindow or (B) Inject your script.

    (A) unsafeWindow looks like:

    unsafeWindow.$(document).ajaxSuccess(function(e, xhr) {
        alert("ajax success hit!");
        // I will do my other handling here
    });
    

    (B) Script injection looks like:

    function scriptWrapper () {
    
        //--- Intercept Ajax
        $('body').ajaxSuccess (
            function (event, requestData) {
                alert ("ajax success hit!");
                doStuffWithAjax (requestData);
            }
        );
    
        function doStuffWithAjax (requestData) {
            console.log ('doStuffWithAjax: ', requestData.responseText);
        }
    
        //--- DO YOUR OTHER STUFF HERE.
        console.log ('Doing stuff outside Ajax.');
    }
    
    function addJS_Node (text, s_URL, funcToRun) {
        var D                                   = document;
        var scriptNode                          = D.createElement ('script');
        scriptNode.type                         = "text/javascript";
        if (text)       scriptNode.textContent  = text;
        if (s_URL)      scriptNode.src          = s_URL;
        if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
    
        var targ    = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
        targ.appendChild (scriptNode);
    }
    
    addJS_Node (null, null, scriptWrapper);
    

    Note that in both cases, you must be conscious that data does not flow from page scope back to GM scope easily — be careful about mixing the two.

    One workaround, for transmitting data across the sandbox, can be found in this answer.

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

Sidebar

Related Questions

I have written a basic Greasemonkey script which passes an output out to a
I have a basic model in which i have specified some of the fields
I have the following fairly basic greasemonkey script: var newloc = location.href.replace(/^(.*)-xyz-(.*)$/i, $1$2); if
Currently, i have basic C++ and PHP skills. But, i want to switch to
I have a basic ActiveRecord model in which i have two fields that i
I'm trying to write a Greasemonkey script for Facebook and having some trouble with
Right now, I have basic code for moving the textfield above the keyboard when
I have basic JavaScript code that needs to tell how many names out of
I have basic question about mysqli prepared statements. For example, I want to execute
I have basic html stored in my database, which includes html such as the

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.