我想使用xmlhttprequest将文本和图像加载到div中,不幸的是,图像onload事件不起作用。
代码是这样的:
<img src="pic.png" onload="alert('...')"/>
请求后我可以看到图像,但是onload事件不会触发——为什么?
我想使用xmlhttprequest将文本和图像加载到div中,不幸的是,图像onload事件不起作用。
代码是这样的:
<img src="pic.png" onload="alert('...')"/>
请求后我可以看到图像,但是onload事件不会触发——为什么?
Can be down to caching. The onload event for images is a bit sketchy and doesn't always fire for AJAX requests.
Try adding a query parameter to the request with the current date to stop any caching