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

  • Home
  • SEARCH
  • 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 6861569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:33:06+00:00 2026-05-27T02:33:06+00:00

I am using JQuery .get method to retrieve some content from a webpage (page

  • 0

I am using JQuery .get method to retrieve some content from a webpage (page 1) and show it in a div in the main page. The problem is the content retrieved contains some javascript calls. The content is being displayed, but the Javascript methods are not getting executed. The .js file is being referenced across all the pages, so the availability of the js in the main is not a problem.

This is the code in the main page. URL of page 1 is given to the .get function:

$.get(url, function(response) {          
    var newContent = $(response).find("#right");      //Find the content section of the response
    var contentWrapper = $("#wrap");         //Find the content-wrapper where we are supposed to change the content.
    var oldContent = contentWrapper.find("#right");   //Find the old content which we should replace.

    oldContent.replaceWith(newContent);
});

This is the code in the #right (div) of Page 1

Some html tags...    
<p><script type="text/javascript">abc7();</script></p>
<p><script>s(30)</script></p>
Some html tags...

The functions abc7 and s are available in a .js (normal javascript file) that is being reference in the section of all pages

The s(30) should display a text field of size 30.

  • 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-27T02:33:06+00:00Added an answer on May 27, 2026 at 2:33 am

    Inline JavaScript won’t execute unless you run eval() on it. You can read more about that here:

    • Executing inside retrieved by AJAX
    • Can scripts be inserted with innerHTML?

    An eval() solution could look something like this, but I would consider it bad practice:

    $.get(url, function(response) {          
        var newContent = $(response).find("#right");      //Find the content section of the response
        var contentWrapper = $("#wrap");         //Find the content-wrapper where we are supposed to change the content.
        var oldContent = contentWrapper.find("#right");   //Find the old content which we should replace.
    
        oldContent.replaceWith(newContent);
    
    
        //Find all inline script tags in the new content and loop through them
        newContent.find("script").each(function() {
            var scriptContent = $(this).html(); //Grab the content of this tag
            eval(scriptContent); //Execute the content
        });
    });
    

    A better solution is to set a identifier/name on the #right tag and execute the code needed for that specific content.

    Something like:

    <div id="right" data-page-name="index">
        <!-- Content -->
    </div>
    
    <div id="right" data-page-name="about-us">
        <!-- Content -->
    </div>
    

    A simple solution that just passes the page name to a function that will execute the code depending on page would look something like this:

    $.get(url, function(response) {          
        var newContent = $(response).find("#right");      //Find the content section of the response
        var contentWrapper = $("#wrap");         //Find the content-wrapper where we are supposed to change the content.
        var oldContent = contentWrapper.find("#right");   //Find the old content which we should replace.
    
        oldContent.replaceWith(newContent);
    
        var pageName = newContent.attr("data-page-name");
    
        pageSpecificActions(pageName);
    });
    
    function pageSpecificActions(pageName) {
        if (pageName == "index") {
            //Run the code for index page
        } else if (pageName == "about-us") {
            //Run the code for about us page.
        }   
    };
    

    This keeps the JavaScript code from being inline and doesn’t use eval(). Even better would be to use events for when page content change, but this will be enough for now.

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

Sidebar

Related Questions

I'm using JQuery's getJSON method to retrieve some data from an MVC controller. [AcceptVerbs(HttpVerbs.Get)]
I am using jQuery's $.ajax method to retrieve some JSON from an API. Each
I am trying to retrieve some data from a database using jQuery's $.getJSON method
I'm using ajax to retrieve some data from the backend. I get the result
I'm trying to pull JSON data from another source by using the jquery.get method.
I am using jquery ajax method to get data from a web method and
I just get the parameters from PHP GET method and use them using jQuery.
I am using ASP.NET page methods with jQuery.... How do I get the value
I am using JQuery to get the contents of a div, which only contains
How to get previous page URL using jQuery? I am using the following code

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.