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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:40:58+00:00 2026-06-06T05:40:58+00:00

Before everyone finds it, this has more or less been asked before: Load remote

  • 0

Before everyone finds it, this has more or less been asked before: Load remote URL with Greasemonkey and jQuery

However, it was 3 years ago. I tried the various methods presented in the answers and none of them work.

Basically, my problem is this: I’m writing a greasemonkey script that, for right now, is supposed to A) grab a link on a page, B) request the page the link is linking to (it’s on the same host), and C) find a certain value on that page. I’m using jQuery 1.7.2 and the latest version of Greasemonkey to try to accomplish this.

The problem is that though I can successfully request the page, I can’t do anything with the response. I’ve tried assigning the response to a variable outside of the callback, but it ends up empty. I’ve tried appending the response html to a div I inserted on the page, but using console.log on the div shows that it’s empty (even though firebug actually shows the html). It’s like as soon as the callback ends, the html that was retrieved not only doesn’t exist, but didn’t ever exist.

So basically, I want to ask how to retrieve the html so that I can actually use it after the request is finished. Here’s what I’ve got right now (I’ve deleted aforementioned attempts to append the response to a div on the page):

function getLink(url){
    var resp;
    GM_xmlhttpRequest({
        method: 'GET',
        url: url,
        onload: function(response){
            resp = response.responseText;
        }
    });
    console.log(resp) //nothing here...

    //failed code :(
    /*$.ajax(url, {success: function(data){resp = data})
    console.log(data)*/
}

What magic code do I need to write to get the above to work as intended?

  • 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-06T05:41:00+00:00Added an answer on June 6, 2026 at 5:41 am

    GM_xmlhttpRequest() operates asynchronously by default. That means that the onload fires long after the console.log(resp) //nothing here... line.

    Although GM_xmlhttpRequest() now takes a synchronous: true parameter, it is very buggy and I do not recommend trying to use it, for now.

    The correct way to do things (and better programing and UI practice) is put everything in the onload handler:

    function getLink (url) {
        GM_xmlhttpRequest ( {
            method: 'GET',
            url: url,
            onload: function (response) {
                var resp = response.responseText;
                console.log (resp);
    
                // DO EVERYTHING THAT REQUIRES resp HERE.
            }
        } );
    }
    

    This may require changing how you think about certain operations, but it is well worth it.

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

Sidebar

Related Questions

This question has been asked many times before but it seems everyone else is
expected unqualified-id before '{' Where is this error on my code? Thanks everyone! #include
Wondering if anyone out there has ran into this before.... I'd like to use
I thought this question was asked before but I tried Google but didn't find
Before Django 1.0 there was an easy way to get the admin url of
Before I throw something ugly together I thought this would be a good one
Before the switch and in all apps on this passenger that run rails 2.0
Hey, everyone. I couldn't find anything Googling this problem, and I've found really good
I've been given the ask of converting an MVP ASP.NET app to Silverlight. This
Merry Christmas everyone. I do have a question before Santa arrives. I'm new with

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.