dongliao1860 2015-01-14 09:30
浏览 47

使用ajax乱码文本显示图像

hope you can help me, i have PHP script that generate image(get image using curl) it is call via ajax,when i directly access the php script(not using ajax) image is successfully generated but when call via ajax it display garbled text. Do you know the reason of this?

PHP SCRIPT:

header('Content-Type: image/jpeg');
header('Content-Length: ' . get_size($songname));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_HTTPGET,1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_exec($ch);
curl_close($ch);

Javascript:

$.post(baseUrl+"getphoto.php",{photo:path }).done(function( data ) {
    console.log('#thumb_'+id);
    //garbled text appear on firebug
}});
  • 写回答

1条回答 默认 最新

  • doufen5175 2015-01-14 09:36
    关注

    you create image dynamically thus you need add header of Content-Type

    header('Content-Type: image/jpeg');
    

    to getphoto.php

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题