I have an img control/element on my asp.net page.
At the moment i am call an ashx handler to retrn a byte array using context type as:
context.Response.ContentType = "image/jpg";
The javascript sets the image like this:
img.src = url + '/Mobile/GetFrame.ashx?';
Is there a way to do the same but using a JQuery/Ajax call instead?
So, for instance:
function GetImage() {
$.ajax({
url: url + '/Mobile/GetFrame.ashx',
type: 'GET',
timeout: freshWaitlimit,
data: lastTS,
success: function (response, status, xhr) {
serverImage1x4.src = response;
},
error: function (jqXHR, textStatus, errorThrown) {
alert('err');
finished = true;
}
});
}
But I get no image. But i get no error either..
I have my solution but it really is not all my own work. Here it is:
function GetImage() {
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.open('GET', url + '/Mobile/LiveXP.ashx?Alias=' + Alias + '&camIndex=' + camIndex + '&Guid=' + createGuid(), true);
xmlHTTP.responseType = 'arraybuffer';
xmlHTTP.timeout = 10000;
xmlHTTP.ontimeout = function () { alert("Timed out!!!"); finished = true; }
xmlHTTP.onload = function (e) {
var arr = new Uint8Array(this.response);
var raw = String.fromCharCode.apply(null, arr);
var b64 = btoa(raw);
var dataURL = "data:image/jpeg;base64," + b64;
serverImage1x4.src = dataURL;
};
xmlHTTP.send();
}