我想在得到 ajax 的响应后显示图像
我有以下代码
<!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>
我不知道,如何显示ajax请求成功的local_image
我在 php 中需要这个,所以它会返回内容类型 jpeg 标头
在你的
成功函数中添加:
$(body).append('<img src="' + local_image + '">');
添加空白图像。
<img id="local_source" style="display:none"/>
在 AJAX 成功函数中:
success: function(data) {
$("#local_source").show().attr('local_source', data[0]['local_source']);
}