jquery - Setting response image of Ajax Request to img tag -


i have image in response server trying add image tag having problems here code:

        $.ajax({             type: "get",             url: "some_image_url",             contenttype: "image/png",             success: function (data) {            var img = new image();                 var url = window.url || window.webkiturl;                 img.src = url.createobjecturl(data);             document.getelementbyid("createthingicon").appendchild(img);             },         }); 

when responded image appended html not showing rather broken image.is there wrong in code? hard coded url can check response

$.ajax({      type: "get",      url: "your_remote_url",      mimetype: "text/plain; charset=x-user-defined",      success: function (data) {           $image = $('<img />').attr('src', 'data:image/png;base64,' + base64encode(data));          $('#createthingicon').append($image);       },  });  function base64encode(str) {     var chars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/";     var out = "", = 0, len = str.length, c1, c2, c3;     while (i < len) {         c1 = str.charcodeat(i++) & 0xff;         if (i == len) {             out += chars.charat(c1 >> 2);             out += chars.charat((c1 & 0x3) << 4);             out += "==";             break;         }         c2 = str.charcodeat(i++);         if (i == len) {             out += chars.charat(c1 >> 2);             out += chars.charat(((c1 & 0x3)<< 4) | ((c2 & 0xf0) >> 4));             out += chars.charat((c2 & 0xf) << 2);             out += "=";             break;         }         c3 = str.charcodeat(i++);         out += chars.charat(c1 >> 2);         out += chars.charat(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4));         out += chars.charat(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6));         out += chars.charat(c3 & 0x3f);     }     return out; } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -