I am trying to get a base64 string of a jpg image from a C# ASP method. I have confirmed that the base64 being returned is actually converted into the image correctly. However, when trying to set it as an 's src through JQuery, I get a BAD REQUEST error in FireBug monitor.
JQuery:
function GetImage() {
$.ajax({
url: "Default.aspx/GetImageArray",
type: "POST",
dataType: "json",
data: "{}",
contentType: "application/json; charset=utf-8",
success: function (msg) {
document.getElementById("MainContent_output").setAttribute('src', 'data:image/jpeg;base64,' + $.fromBASE64(msg['d']));
},
error: function (e) {
alert(JSON.stringify(e));
}
});
}
C# ASP:
[WebMethod]
public static string GetImageArray()
{
return Convert.ToBase64String(File.ReadAllBytes(path));
}
Don't mind the 'GetImageArray' name, the method returns a string.
Well, SOS pretty much :)