I have a php file at path/renderer/renderImage.php
that builds and returns a PNG image to the browser. When I navigate to that URL with my browser, it dumps the correct image on the screen. But when I try to load that image into a DIV with jQuery using the code below from path/index.html ...
我在path/renderer/renderImage上有一个php文件。构建并返回PNG图像到浏览器的php。当我用浏览器导航到那个URL时,它会在屏幕上转储正确的图像。但是,当我尝试使用下面的代码从路径/索引中加载该图像到一个DIV中。html……
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
....
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../jquery.colorbox.js"></script>
<script>
$.colorbox({
width:"30%",
inline:true,
href:"#inline_content",
onClosed: function() {
$("#myPic").load('./renderer/renderPicture.php');
$('#myPic').css('display','inline');
}
});
it fills the DIV with strange symbols...
它用奇怪的符号填满了DIV。
Here is a picture of the directory structure:
这是目录结构的图片:
Why is the browser interpreting the picture differently on these two pages? What might cause the discrepancy?
为什么浏览器在这两页上对图片的解释是不同的?什么会导致这种差异?
2 个解决方案
#1
2
You are getting symbols instead of an image since you are trying to send binary data without specifying what that data is.
您正在获取符号而不是图像,因为您试图发送二进制数据而不指定数据是什么。
Add header to your renderPicture.php file :
添加标题到你的效果图。php文件:
header('Content-Type: image/png');
And it will return the desired png image.
它将返回所需的png图像。
Cheers
干杯
#2
1
The jQuery .load method will load TEXT/HTML content and insert it into the document. This is exactly what happens in your case, and is expected behavior.
load方法将加载文本/HTML内容并将其插入到文档中。这正是在你的案例中所发生的,并且是预期的行为。
To load an image via jQuery you can use:
要通过jQuery加载图像,您可以使用:
$('<img src="./renderer/renderPicture.php">')
and then make use of the .load (event) to do something:
然后利用.load(事件)来做一些事情:
$('<img src="./renderer/renderPicture.php">').load(function() {
$(this).appendTo('#myPic');
});
See here: https://*.com/a/10863680/2327283
在这里看到的:https://*.com/a/10863680/2327283
#1
2
You are getting symbols instead of an image since you are trying to send binary data without specifying what that data is.
您正在获取符号而不是图像,因为您试图发送二进制数据而不指定数据是什么。
Add header to your renderPicture.php file :
添加标题到你的效果图。php文件:
header('Content-Type: image/png');
And it will return the desired png image.
它将返回所需的png图像。
Cheers
干杯
#2
1
The jQuery .load method will load TEXT/HTML content and insert it into the document. This is exactly what happens in your case, and is expected behavior.
load方法将加载文本/HTML内容并将其插入到文档中。这正是在你的案例中所发生的,并且是预期的行为。
To load an image via jQuery you can use:
要通过jQuery加载图像,您可以使用:
$('<img src="./renderer/renderPicture.php">')
and then make use of the .load (event) to do something:
然后利用.load(事件)来做一些事情:
$('<img src="./renderer/renderPicture.php">').load(function() {
$(this).appendTo('#myPic');
});
See here: https://*.com/a/10863680/2327283
在这里看到的:https://*.com/a/10863680/2327283