0

Is there any way I can use the .load event(or any other jquery event) with a dynamic image such as this

Whenever I try to use the .load or .get method to reload that page into the document it just come out as �������� in Firefox and �PNG in internet explorer.

What am I missing here? What would be the best way to do this?

Overall what I'm trying to accomplish here is to reload the captcha.php file into a div when a link is clicked and have a different captcha image be shown without refreshing the page.

The problem can be found here
http://www.seewhosoutthere.com/createAccount

clicking on the little blue "refresh" button next to the captcha will give the result I'm talking about.

The code currently being used for that page is

$('a#refresh').click(function(){
    $('#captcha').load('captcha.php');
});
Ryan
  • 243
  • 2
  • 15

1 Answers1

5

Instead of .load() (which isn't intended for binary data...which is why you get those fun symbols with the encoding) you just need to create an <img> element with the right src and put it where you want in the document, for example:

$("<img />", { src:"http://www.seewhosoutthere.com/captcha"}).appendTo("#myDiv");

You can test it out here.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • Hey nick, the problem with that is then it adds another captcha image(with the same security) to the same div so there are multiple images. – Ryan Dec 06 '10 at 04:25
  • @Ryan - Oh if you want to replace it, just do `$('#myDiv').html($("", { src:"http://www.seewhosoutthere.com/captcha"}));`, or call `$('#myDiv').empty()` before...whichever :) – Nick Craver Dec 06 '10 at 04:28
  • But that still only loads the identical captcha image, the image is not refreshed with a new code. – Ryan Dec 06 '10 at 04:31
  • 2
    @Ryan - if you want to load a new one you need to put a cache breaker on the URL, like this: http://jsfiddle.net/nick_craver/hQ8y2/2/ – Nick Craver Dec 06 '10 at 04:35
  • interesting. I've never heard of a thing like that. I'll have to do some research on that. Thanks much sir, that solved my problem. – Ryan Dec 06 '10 at 04:43