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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:16:10+00:00 2026-05-17T23:16:10+00:00

OK, I’m actually calling some java middleware that returns a captcha image. The captcha

  • 0

OK, I’m actually calling some java middleware that returns a captcha image. The captcha image loads in the page on page load simply with:

<a href="#" id="ci"><img id="stickyImg" src="stickyImg" /></a>

I want to reload the captcha image onclick of the current captcha image. I’ve tried a few things but am not getting anything working.

By “tried a few things” I mean I have tried:

$("#ci").click(function(){

        $("#stickyImg").load('stickyImg');

        return false;
    });

which indeed loads the image but it does it by placing the raw binary image data inside the image tag so I get:

<img src="stickyImg"><img xmlns="http://www.w3.org/1999/xhtml">pngbinarygibberishsymbols</img>

Hmmm… maybe I need to specify putting the image into the src attribute? Perhaps? What do you all think?


EDIT:

Ugh! Putting the response into my img src results in:

<img src="    * captcha image�PNG  ��� IHDR�������Ketc, etc">

The raw binary data being output. What the heck?


SOLUTION:

The solution comes from another, similar, post I made on this. You can read about it here.

In the end the (*edited thanks to Lee) code that works looks like:

$("#ci").click(function(){

        $("#stickyImg").attr('src', 'stickyImg?' + (new Date().getTime())); 
        return false;
    });
  • 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-17T23:16:11+00:00Added an answer on May 17, 2026 at 11:16 pm

    it would be helpful if you would post a more complete example including the markup that embeds your image in the initial document; but making a few reasonable assumptions, I think you just need something like the following…

    assuming that your markup is something like:

    <div id="ci">
      <img src="/stickyImage" />
    </div>
    

    then the following JS should do the trick:

    $("#ci").click(function(){
    
        $("img",this).remove();
        $(this).html('<img src="/stickyImage" />');
    
        return false;
    });
    

    good luck.


    [edit] If you’re using this code to load an image that’s generated dynamically on your server (or that may change periodically, for some reason), then you’ll also want to be sure that you properly account for the browser’s tendency to cache data that it believes to be static. There are two way that this is commonly accomplished (either will work):

    1) ensure that the url is always different every time the image is loaded. You can do this easily, by just appending a random number to the query string portion of the image url. So, in the above example, $(this).html('<img src="/stickyImage" />'), would become $(this).html('<img src="/stickyImage?"+(new Date().getTime()) />'). (This is essentially identical to the approach that the OP ultimately settled on — see OP’s edits above).

    2) ensure that the server returns the image data, including the proper HTTP headers in the response to indicate that the image is dynamic and shouldn’t be cached. You can see more details about how to send no-cache headers on this SO post.

    Here’s how you would set the needed headers from within a Java servlet:

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
    

    Option #2 is perhaps the more “technically correct” way to address the caching issue, but as I said above – either will work, and option#1 is a very reliable approach that is often substantially easier than option #2.

    All this being said – the caching issue is a separate issue from the original question that was asked here. The original question involved display of binary blobs inline in the HTML. That problem resulted from the incorrect use of the jquery load() function. The OP settled on an approach that uses the attr() function to set the src attribute. The approach I’ve shown involves creating a new img element, and removing the old element. Either of these approaches will work, but the load() function will not work for this purpose.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.