[Solved] Image not displaying in Image control using JQuery Ajax in ASP.Net

Last Reply one month ago By dharmendr

Posted one month ago

Save Binary Data in Database and display Image Using Jquery using jquery1.8.3 

    function DisplayImage(ArtNo) {
        $.ajax({
            type: "POST",
            url: currLoc + '/SetArt_NoImg',
            contentType: 'application/json; charset=utf-8',
            data: "{ 'ArtNo': '" + ArtNo + "'}",
            dataType: 'json',
            success: function (data) {
                alert(data.d);
                if (data.d != null) {
                    $("[id*=Image1]")[0].src = data.d;
                }
            },
            failure: function (response) {
                alert(response.d);
            }
        });
    }

it is return string. so it is not displayed.

    public static string SetArt_NoImg(string ArtNo)
    {
        string str = "";
        DAL dl = new DAL();
        BAL bl = new BAL();
        DataSet dsGetArtImg = new DataSet();
        bl.ArtNo = ArtNo.Trim();
        dsGetArtImg = dl.ENGG_Cut_ImgArt(bl);
 
        if (dsGetArtImg.Tables.Count > 0)
        {
            if (dsGetArtImg.Tables[0].Rows[0]["Img"].ToString() != "")
            {
                return JsonConvert.SerializeObject("data:image/jpg;base64," + Convert.ToBase64String((byte[])dsGetArtImg.Tables[0].Rows[0]["Img"]));             
            } 
        }
        return str;         
    }

 

Posted one month ago

You need to set maxJsonLength property.

Refer below article.

ASP.Net AJAX Error: The length of the string exceeds the value set on the maxJsonLength property