使用AJAX返回时,JQuery mobile弹出窗口不工作
我对AJAX返回的Jquery mobile弹出式html代码有问题。我需要为我正在做的一个移动应用程序调用一个php页面,该页面从mysql数据库获取文本和图像链接(这些链接总是在变化) 我的代码基于这个jfiddle: 以下是由AJAX返回时不起作用的代码:使用AJAX返回时,JQuery mobile弹出窗口不工作,jquery,ajax,mobile,Jquery,Ajax,Mobile,我对AJAX返回的Jquery mobile弹出式html代码有问题。我需要为我正在做的一个移动应用程序调用一个php页面,该页面从mysql数据库获取文本和图像链接(这些链接总是在变化) 我的代码基于这个jfiddle: 以下是由AJAX返回时不起作用的代码: $.ajax({ url:“/echo/html/”, 数据:{ html:' }, 键入:“POST”, 成功:功能(msg) {document.getElementById(“target”).innerHTML=msg; }
$.ajax({
url:“/echo/html/”,
数据:{
html:'
},
键入:“POST”,
成功:功能(msg)
{document.getElementById(“target”).innerHTML=msg;
}
});
有解决办法吗
谢谢。上面的
数据
键是发送到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');
}
});
$.ajax({
url:“/echo/html/”,
数据:{
someParam1:'someValue1',
someParam2:'someValue2',
}
键入:“POST”,
成功:功能(msg){
popupHTML='';
//将popupHTML插入目标
$('#target').HTML(popupHTML);
//然后触发create事件,使jQM标记正确插入html并附加正确的事件等。
$('#target').triggert('create');
}
});
更多信息:
谢谢Rob,我不知道触发功能。我用以下代码实现了它:
$.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');
}
});
$.ajax({
url:“/echo/html/”,
数据:{
html:'
},
键入:“POST”,
成功:功能(msg)
{
$('#target').html(msg);
$('#target')。触发器('create');
}
});
$.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');
}
});