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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:13:58+00:00 2026-06-07T20:13:58+00:00

I have the below code that I was helped with on a previous question

  • 0

I have the below code that I was helped with on a previous question (http://stackoverflow.com/questions/10920514/using-ajax-jquery-to-refresh-an-image)

The way this worked was that image_feed.php returned a url to an image. The snippet below downloaded this image, and then swapped it out with an existing image on the page.

I have now changed the way my application works, and the URL of the image will not change as before so I can bypass the image_feed.php script.

So I have a image, image.php?id=11, and I need to download this image, wait for it to finish loading and then swap it with the #camera_image_changer image.

I am struggling with two things. One is remembering how the script actually works again so as I can give it the image URL directly and secondly preventing it caching the image.

Any help would be greatly appreciated.

Thanks

// image feed
var $img = $('#camera_image_changer'); 

 setInterval(function() {

    $.get('../helpers/image_feed.php?camera_id=11', function(data) {
    var $loader = $(document.createElement('img'));

     $loader.load(function() {
        $img.attr('src', $loader.attr('src'));
     });

     $loader.attr('src', data);

    });

}, 5000);

Update: I may have answered my own question. I have the below code and it is working, is this a OK way to do it?

// image feed
var $img = $('#camera_image_changer'); 

setInterval(function() {

        var $loader = $(document.createElement('img'));

        $loader.load(function() {
            $img.attr('src', $loader.attr('src'));
        });

        $loader.attr('src', '../helpers/image.php?<?=$resource;?>=<?=$resource_id;?>');

}, 5000);
  • 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-07T20:13:59+00:00Added an answer on June 7, 2026 at 8:13 pm

    You can remove the get call and use only the code inside of it, assigning the data variable the path to the image:

    var $img = $('#camera_image_changer');   
    
    // this delay the code execution in milliseconds
    setInterval(function() { 
        var data = "path/to/image.jpg";
    
        // Creates an image object and pass it to jQuery return a jQuery object
        var $loader = $(document.createElement('img')); 
    
        // Create a callback that fires when the image finishes loading
         $loader.load(function() { 
            // assign the source of the loaded image to the target image
            $img.attr('src', $loader.attr('src')); 
         }); 
    
         // assign the image to load
         $loader.attr('src', data);
     }, 5000); // 5 seconds (5000 ms)
    

    In your previous code, the get method calls the page and returns the contents as the data variable.

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

Sidebar

Related Questions

I have this javascript code below that uses jquery, it is suppoed to be
Hi all I have found some really good code over on http://apptools.com thats helped
I have the code below that hides and shows the navigational bar. It is
below i have a code that runs in most of my simple programs ..
Background: I have a WPF UserControl (MainControl - not shown in code below) that
I have the code below on form so that the user submits the form
I have the code below. I'm wondering that does the self.value and _value have
I have a plot (sample code pasted below) that I am trying to add
The code below works great. I have a MySQL database that contains book titles
I have a data that looks like this . And my code below simply

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.