#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    277
    Rep Power
    0

    Image verification in ajax


    resim.php
    PHP Code:
    <?php
    ######################## PHP hata raporlalama #############################
    error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE);

    //Outurum başlıyor
    session_start();

    //rastgele içeriği oturuma (SESSION) yaz
    $_SESSION["rip"] = $_POST["num"];

    ################### Resmi çiz ##########################################
    header("Content-type: image/png");
        
    $image        imagecreatetruecolor(7518) or die("GD Library hatasi"); //resim boyutu   
        
    $fcolor     imagecolorallocate($image255255255);    //Yazı rengi   
        
    $bcolor     imagecolorallocate($image999999); //arkaplan rengi
    imagefilledrectangle($image00300100$bcolor); //resmin arkaplanı
    imagettftext($image1201014$fcolor"arial.ttf",$_POST["num"]);
    imagepng($image);
    imagedestroy($image);


    ?>

    js file

    Code:
    <script language="javascript">
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                url: "font/resim.php",
                dataType: "html",
                data: {
                    num: numRand
                },
                success: function (data) {
                    $("#son").html('<img src="font/resim.php"/>');
                },
                error: function (data, textStatus) {
                    $("#son").html(data);
                }
            });
    
    
        });
    </script>
    </head>
    <body>
        <button id="getit">Generate!</button>
        <div id="randomnumber"></div>
        <button id="b2">Oku</button>
        <div id="son"></div>
    </body>
    i can send random number to php file using ajax but i can not call back data as image. (it is like following)

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    You mightn't need to use the ajax function.

    If you can change your php script to use 'get' instead of 'post' you could use something like this:
    Code:
    $("#b2").click(function() {
      $("#son").html('<img src="font/resim.php?num=' + numRand + '" />');
    });
    Assuming 'numRand' is available elsewhere on your page, when 'b2' is clicked 'son' is filled with the img tag, you can set the src attribute to the url of your php script plus the random number in the query string, it should then be displayed.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    277
    Rep Power
    0
    Originally Posted by Edge360
    You mightn't need to use the ajax function.

    If you can change your php script to use 'get' instead of 'post' you could use something like this:
    Code:
    $("#b2").click(function() {
      $("#son").html('<img src="font/resim.php?num=' + numRand + '" />');
    });
    Assuming 'numRand' is available elsewhere on your page, when 'b2' is clicked 'son' is filled with the img tag, you can set the src attribute to the url of your php script plus the random number in the query string, it should then be displayed.

    result is same. it did don run.

    when i tried following
    Code:
    $("#son").html("<img src="+ $.trim( data ) +" />");
    it gives following result


  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    Code:
    $("#son").html("<img src="+ $.trim( data ) +" />");
    is from the reply you got over on the jQuery forums?

    Did any errors appear in the console when running the code from my reply? Did you change the php script to use get instead of post? Is the numRand variable in scope?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    277
    Rep Power
    0
    full code is in attachment
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo