2013-12-14 46 views
0

我正在使用iFrame顯示驗證碼圖像。我想改變一個JQM顯示,我在pagebeforeshow事件中生成圖像。當前代碼,在生成的驗證碼圖像的php程序是:Jquery Mobile顯示生成圖像

$im=genCaptcha(); 
print base64_encode(imagepng($im)); 
imagedestroy($im); 

genCaptcha()功能是在一個包含文件。它使用GD庫函數來創建圖像。

這是我在pagebeforeshow事件處理代碼:

$(document).on('pagebeforeshow','#addList', function(){ 
    $.post('displaycaptcha.php','',function(data) { 
     $("#rList").html('<img src="data:image/png;base64,' + data + '" />'); 
     }); 
    }); 
}); 

任何意見或幫助將不勝感激。

回答

0

賓果:這裏是在PHP腳本工作(JavaScript的問題不變):

ob_start(); 
imagepng($im);      
$image = ob_get_contents(); 
ob_end_clean(); 
print base64_encode($image); 
imagedestroy($im);