jquery .load dynamic image

浪子不回头ぞ 提交于 2019-12-11 15:13:24

问题


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');
});

回答1:


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.



来源:https://stackoverflow.com/questions/4362820/jquery-load-dynamic-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!