简体   繁体   中英

JQuery ajax call not rendering the html

I am making an ajax call to the database server to get the image as a base64 encoded string, the server is returning the base64 encoded image correctly I did check this in firebug, I need to use this encoded string as an hyper reference of an anchor on a page.

here is my client code

$.ajax({
        url: '../Handlers/ImageHandler.ashx',
        data: { ID: imageId },
        type: 'GET',
        dataType: 'text/plain',
        success: onAjaxSuccess,
        error: onAjaxFail
    });

function onAjaxSuccess(result) {
    var anchor = document.getElementById('hlImage0');

    var base64Image = 'data:image/png;base64,' + result;
    anchor.href = base64Image;
}

The problem here is the anchor element hlImage0 is not setting the href property and nothing is rendered on the page from the onAjaxSuccess callback.

Image balise have on href attribute !

Try changing anchor.href by anchor.src instead !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM