成功ajax进程后如何显示图像

时间:2011-07-07 18:58:06

标签: javascript ajax

我想在向数据库提交数据后显示qrcode 这是我提交的代码:

 $(document).ready(function(){
       $("input#submitmap").click(function() {
            var routedmap = 
                {
                 destination :destinationDB,
                 point: addressRoute

                };

            $.ajax({
              type: 'POST',
              url: 'addroutedmap.php',
              data: routedmap,
            success: function(data){


            }
            });
        });

    });

在提交后的成功功能中,我想显示qrcode的图像,这里是图像的代码:

<img src="https://chart.googleapis.com/chart?
cht=qr&amp;chs=200x200&amp;chl=http://www.facebook.com"></img>

我尝试过使用.show .html(+ data +)但它不起作用。 有任何想法或建议吗?

2 个答案:

答案 0 :(得分:2)

你试过这个:

$('body').append('<img src="https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=http%3a%2f%2fwww.facebook.com" />');

或:

$('#container').html('<img src="https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=http%3a%2f%2fwww.facebook.com" />');

其中#container是隐藏图像的DOM元素。

或我喜欢的方式:

$('#container').html(
    $('<img/>', {
        src: 'https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=http%3a%2f%2fwww.facebook.com',
        alt: ''
    })
);

答案 1 :(得分:0)

$('#div_where_you_will_sho_qr_code').append(data.toString());
相关问题