简体   繁体   English

jQuery ajax调用未呈现html

[英]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. 我正在对数据库服务器进行ajax调用,以将图像作为base64编码的字符串获取,服务器正确返回了base64编码的图像。在页面上。

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. 这里的问题是锚元素hlImage0没有设置href属性,并且onAjaxSuccess回调在页面上未呈现任何内容。

Image balise have on href attribute ! 图像平衡具有href属性!

Try changing anchor.href by anchor.src instead ! 尝试anchor.href通过anchor.src更改anchor.href

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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