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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:41:59+00:00 2026-06-07T11:41:59+00:00

I am currently using Jquery’s .load() function to insert a page fragment asynchronously. In

  • 0

I am currently using Jquery’s .load() function to insert a page fragment asynchronously. In the URL that I am loading the page fragment from, I also set a Javascript global variable value (in the script tag).

var loaded_variable = 'value1'

Is there a way I can use the .load() function to insert the page fragment AND retrieve the value of loaded_variable, something like the following code:

    function loadProducts(url) {
                 $('#mainplace').load(url + ' #submain', function() { 
                       current_variable = loaded_variable;
                 });
    }

I am aware that script blocks are used when a selector expression is appended to the URL, so if the .load() function won’t work, I’m open to other Jquery functions that can accomplish this.

Extra Info: The URL that I am loading from is written in HTML and Python (Web2py); the same Python variables are used to render the page fragment and set the loaded_variable value.

  • 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-07T11:42:01+00:00Added an answer on June 7, 2026 at 11:42 am

    If you want to both fetch a fragment from a page and execute a script on it, you’ll need a different approach. This is a bit hacky, but works.

    $.ajax({url: 'fetch_page.html', dataType: 'text'}).done(function(html) {
        var dom = $('<html />').prop('innerHTML', html);
        $('body').append(dom.find('body p'));
        $('head').append(dom.find('script'));
    });
    

    That fetches a p tag from our fetched pages and inserts it into the body of the parent page. It also executes any scripts in the fetched page.

    If you’re wondering about the prop('innerHTML... bit, that’s because if I’d used jQuery’s .html() method, it sanitises the input string and so we don’t get the result we want.

    My first thought was a document fragment, but you can’t insert an HTML string into a doc frag – you have to append via DOM methods. Even then in this case it wouldn’t really offer any saving over simply using an element to parse the dom (dom) as I have.

    Bit hacky, as I say, but works.

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

Sidebar

Related Questions

I am trying to load a part of the page using jQuery load function
I am currently using jQuery to load a page at a specific hashtag (via
I'm currently using jQuery Cookies plugin, and depending on which side of the page
I am currently using jQuery to load a variable php layout depending on the
I am currently using jquery ui datepicker for forms that have date inputs. The
Hi I am currently using jQuery to load a variable php layout depending on
I am currently using jquery slideonlyone function. I am having problems implementing an expanding/collapsing
I am currently using jquery function(below) to display a block on click of a
I'm currently using jquery's ajax feature or whatever they call it. To load data
I'm using jQuery's AJAX function, like so: $.ajax ({ url : /note, async :

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.