Santhosh Subramaniam

Santhosh Subramaniam

  • NA
  • 226
  • 107.9k

Load Image from handler using JQuery

May 6 2015 8:40 AM
Hi Frnds,

        In my project i want to bind image from handler file(.ashx)  in asp.net , i want to call that file in JQuery and bind image.

sample Code: 

         In .ashx file 

               public void ProcessRequest(HttpContext context)        {
            context.Response.ContentType = "image/*.";
            byte[] filecontent = File.ReadAllBytes(@"D:\Sample\LoadImageInAJAX\LoadImageInAJAX\Desert.jpg");
            context.Response.BinaryWrite(filecontent.ToArray());
        }

        In .html File

       $(document).ready(function () {
            $.ajax({
                url: "LoadImage.ashx",
                type: "GET",
                dataType: "binary",
                processData: false,
                success: function (result) {
                    var data = result;
                    // do something with binary data
                },
                error: function (xhr) {
                    alert("Error occurred while loading the image. "
                        + xhr.responseText);
                }
            });
        }); 


I got an error is responseText is : JFIF.


Please help me out.
Thanks in Advance.

Answers (1)