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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:42:26+00:00 2026-06-12T08:42:26+00:00

Using jQuery 1.7.3 I’ve recently replaced a $.load(); call with a $.get(); in one

  • 0

Using jQuery 1.7.3

I’ve recently replaced a $.load(); call with a $.get(); in one of my scripts to take advantage of request aborting and other cool features – so I’m requesting a normal (php in this case) html page rather than a file that returns JSON or XML.

But I’ve noticed that a script error on the page you are loading – for example onError='myFunction(this);' inline scripts that call a function not defined on page1 but present on page2, can throw an error (in this case, undefined function myFunction) on page1. Also I see the images are requested too.

My use case is that I need one div worth of data from the new page, not the whole thing and certainly not the images – is there a way to get jQuery to request only the markup and not ‘follow’ the image links, nor attempt to run any inline scripts?

Example:

Page1:
$.get('page2', {someData:123}, function(data){
    var myDiv = $('#myDiv', data); //get the div I want from the response

    //but at this point the browser has run the inline 
    //scripts and requested the images :(
    //do something with the (very expensive) data

    $('body').append(myDiv);
});

Page2:
<div id='myDiv'>
  <!-- some dynamic data that changes over time -->
</div>

There are some concerns about whether I should just write (yet another) file I can query with JSON to get the data I need, then parse it in the script and generate the markup, etc etc, but sufficed to say in this use case that would be far more trouble than it’s worth, especially considering I’d be replicating code too.

With regards the inline scripts, I can (and have, as a workaround) just define the function on page1 to avoid the error.

Any help appreciated

  • 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-12T08:42:27+00:00Added an answer on June 12, 2026 at 8:42 am

    The best way to do this that I eventually found is pretty simple – when you make an AJAX request to a page, send in an extra parameter that stops your page from outputting data you don’t need.

    Page1:
    $.get('page2', {someData:123, ajax:true}, function(data){
        var myDiv = $('#myDiv', data); //get the div I want from the response
        $('body').append(myDiv);
    });
    
    Page2:
    <?php if (isset($_GET['ajax'])) { ?>
      <div id='myDiv'>
        <!-- some dynamic data that changes over time -->
      </div>
      <?php exit(); ?>
    <?php } else { ?>
      //show the page as normal
    <?php } ?>
    

    This approach is a pain to implement, but does the job and is nice and efficient when you have a very big search page that does all sorts of extra stuff, but all you want is the next page of results.

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

Sidebar

Related Questions

Using jQuery, how can I get the selected item's value in a select when
Using jQuery, how can I get the input element that has the caret's (cursor's)
Using jQuery, one can easily find out whether a particular element is visible using
Using JQuery I am trying to perform validation and also get the values of
using jquery ui tabs , when you load a tab in ajax, the tab
I am reading a book about Javascript and jQuery and using one of the
Using Jquery AJAX to get a value from a PHP script. This line works
Using jquery, I want to post data to from one of my pages to
Using jQuery to make an AJAX call to a PHP file results in the
Using jquery, I'd like to get all elements in a specified columns of an

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.