Hitu Bansal Hitu Bansal - 5 months ago 12
Ajax Question

Want to show image , after getting image name using ajax, not want to return html

I want to show image after getting response from ajax

I have following code

<!DOCTYPE html>
<html>
<title> Dashboard</title>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
jQuery(document).ready(function() {
url = "<?php echo $_GET['PATH_INFO']; ?>";
$.ajax({
type: "POST",
url: 'http://localhost:8081/fetch_image',
dataType: "JSON",
data: {
external_source: url,

},
success: function(data) {
local_image= data[0]['local_source'];
alert(local_image);
}
});

});
</script>
</head>
<body>


</body>


I have no idea, how to show local_image on success of ajax Request

I need this in php so it will return content type jpeg header

Answer

in your success-function add:

$(body).append('<img src="' + local_image + '">');