2013-08-28 44 views
2

我遇到AJAX返回的JQuery移動彈出窗口HTML代碼問題。我需要這個移動應用程序,我要做的就是調用一個從mysql數據庫獲取文本和圖像鏈接的php頁面(這些將始終在改變)。當使用AJAX返回時,JQuery移動彈出窗口不工作

我已經在此基礎上jfiddle我的代碼:http://jsfiddle.net/wbfqy/

這裏是當AJAX返回工作不相同的代碼:http://jsfiddle.net/NF2jz/4392/

$.ajax({ 
    url: '/echo/html/', 
    data: { 
     html: '<div data-role="content"><a href="#TEST_about" data-role="button" data-rel="popup">Popup</a><div data-role="popup" id="TEST_about" data-theme="d" ><a href="#" data-rel="back" data-role="button" data-theme="d" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a><img src="http://www.illinoisci.com/files/cellphone.gif" width="157" height="88" class="popphoto" /></div></div>' 
    }, 
    type: 'POST', 
    success: function(msg) 
    {  document.getElementById("target").innerHTML=msg; 
    }    
}); 

有沒有解決辦法?

謝謝。

回答

0

感謝羅布我沒有了解觸發功能。我得到它與以下代碼工作:

$.ajax({ 
    url: '/echo/html/', 
    data: { 
     html: '<div data-role="content"><a href="#TEST_about" data-role="button" data-rel="popup">Popup</a><div data-role="popup" id="TEST_about" data-theme="d" ><a href="#" data-rel="back" data-role="button" data-theme="d" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a><img src="http://www.illinoisci.com/files/cellphone.gif" width="157" height="88" class="popphoto" /></div></div>' 
    }, 
    type: 'POST', 
    success: function(msg) 
    {  
    $('#target').html(msg); 
    $('#target').trigger('create'); 
    }    
}); 
0

您上面的data鍵是您發送到PHP腳本的數據。

因此,以後插入彈出窗口,您可以將其添加如下。請注意,雖然你不發送任何具體或現在與接收msg參數做任何事情:

$.ajax({ 
    url: '/echo/html/', 
    data: { 
     someParam1: 'someValue1', 
     someParam2: 'someValue2', 
    } 
    type: 'POST', 
    success: function (msg) { 
     popupHTML = '<div data-role="content"><a href="#TEST_about" data-role="button" data-rel="popup">Popup</a><div data-role="popup" id="TEST_about" data-theme="d" ><a href="#" data-rel="back" data-role="button" data-theme="d" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a><img src="http://www.illinoisci.com/files/cellphone.gif" width="157" height="88" class="popphoto" /></div></div>'; 
     //insert the popupHTML into the target 
     $('#target').HTML(popupHTML); 
     // then trigger the create event to make jQM markup the insert html properly and attach the correct events etc. 
     $('#target').triggert('create'); 
    } 
}); 

更多信息:

jQuery Ajax

jQM trigger