I have a php script that randomly generates an image. Something like this:
<?php
$image = imagecreatetruecolor(400,200);
// process image
// rendering image
header("Content-type: image/jpeg");
imagejpeg($image);
?>
My html looks like this:
<img id="image" src="/models/plugins/image.php"/>
<button id="button">Get new image</button></body>
Then I have a jquery file that handles the click to the button, so that a new random image is loaded when the button is clicked:
$(function(){
$('#button').click(function(){
$.ajax({
url: 'models/plugins/image.php',
success: function(data){
$('#image').html('<img src="' + data + '">')
}
})
})
})
I use firebug, I can see that request is actually sent and that the response is received successfully, but the image does not change.
What am I doing wrong and how can I fix this?