I have a PHP script that creates and image using the imagick PHP extension. I display the image on page load like so:
<img id="myImage" src="php/image-script.php" />
The PHP script ends by echoing the imagick image object that is built in the script:
echo 'myImage';
This all works fine on page load. I have now added a jQuery AJAX request which is fired when tabbing out of an input box. The value of the input box is then passed through to the image-script.php via a query string like so:
$('#inputHeight').on('blur', function(){
var $height = $('#inputHeight').val();
$.ajax({ url: './php/preview-image.php?h=' + $height,
type: 'post',
success: function(output) {
$('#preview').attr('src', output);
}
});
});
My problem comes in the success function of the AJAX request. Currently i'm updating the img src attribute with the output (as above). This is simply writing the raw string value of the image into the attribute and it is not updating. How would I go about updating the image correctly?