Help us understand the problem. What is going on with this article?

PHPとAjaxでバイナリ?

More than 5 years have passed since last update.

あるところの質問に想像働かせて答えてみる。多分画像がやりたいんだろうと思ってるんだけど、こうすかね。

html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Download Image</title>
        <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
        <script>
            function download(){
                var image = new Image();
                image.src = 'image.php'
                image.onload = function(){
                    $('#result').append(image)                      
                    alert('downloaded');
                    image = null;
                }
            }
        </script>

    </head>

    <body>
        <button onclick="download()">Download</button>
        <div id="result">
        </div>
    </body>
</html>
php
<?php
    header('Content-type: image/jpeg');
    readfile('fish.jpg'); //画像用意してね   
?>
ms2sato
何でも屋だが、最近はRails中心。JavaScript好き。レビューやタスク分解が多くて近頃仕事ではコード書けていない。仕事でもプライベートでもコラボできる人が常に欲しい人。 会社では人を育てるの中心で https://circlearound.co.jp/training/ こんなのやってます。 独り言はこっち https://ms2sato.circlearound.co.jp
https://circlearound.co.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away