2011-07-07 65 views
0

我想以後我的數據提交到數據庫 顯示一個QRCode的,這是我提交的代碼:如何顯示成功AJAX處理後的圖像

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

       }; 

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


      } 
      }); 
     }); 

    }); 

在成功提交功能後,我QR碼的想顯示圖像,這裏是圖像的代碼:

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

我已經使用.show的.html(+數據+)和它不工作嘗試。 有沒有任何想法或建議?

+0

究竟是什麼數據?是否字符串? – Patricia

回答

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: '' 
    }) 
); 
+0

圖片標籤以'/>'結尾,而不是'' – brenjt

+0

它顯示出來了,謝謝! – kmtgt

+0

@tgt,如果這篇文章是有幫助的,你可以考慮[標記爲答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)通過點擊勾號在它的旁邊。 –

0
$('#div_where_you_will_sho_qr_code').append(data.toString()); 
+0

.append()正在工作,謝謝:) – kmtgt

+0

不客氣。 –