Jquery移动转换在ajax调用后停止工作
我在一个JQM网站上工作,我遇到了一件非常奇怪的事情,我不确定是什么原因造成的 当我试图在通过ajax加载的页面上使用一个JQM数据转换时,问题就出现了。我的过程如下。单击链接时,我使用Ajax重写容器div,以便显示的数据是动态的,我使用JQM处理转换 下面是我的代码:Jquery移动转换在ajax调用后停止工作,jquery,ajax,jquery-mobile,Jquery,Ajax,Jquery Mobile,我在一个JQM网站上工作,我遇到了一件非常奇怪的事情,我不确定是什么原因造成的 当我试图在通过ajax加载的页面上使用一个JQM数据转换时,问题就出现了。我的过程如下。单击链接时,我使用Ajax重写容器div,以便显示的数据是动态的,我使用JQM处理转换 下面是我的代码: <script type="text/javascript"> function setContent(command,value,url,target){
<script type="text/javascript">
function setContent(command,value,url,target){
$.ajax({
url: url,
type: "post",
data: 'value='+value+'&command='+command,
beforeSend: function() {
$.mobile.loading('show');
},
success: function(response, textStatus, jqXHR){
console.log("sucess");
replaceHtml(target,response);
},
error: function(jqXHR, textStatus, errorThrown){
console.log("error occured:"+textStatus, errorThrown);
},
complete: function(){
$.mobile.loading('hide'); //;
//$.mobile.changePage( "about/us.html", { transition: "flip"} );
}
});
}
function replaceHtml(object,html){
$(object).html();
$(object).html(html);
}
function checkhash(){
if ($('#loadedpage').html() == '') document.location.href = "#home";
}
//$(function(){
$(document).live('pageinit', function(){
checkhash();
$(".navlink").live("click", function() {
var command = $(this).data("command");
var value = $(this).data("value");
var url= $(this).data("url");
var target = $(this).attr("href");
//alert(command+" "+value+" "+url+" "+target);
setContent(command,value,url,target);
});
});
</script>
我在ajax的完整调用中添加了$.mobile.changePage()。内容加载良好。。但仍然没有过渡效应
乐叹
编辑:
经过更多的测试,我发现$(document).on('pageinit',函数(e){alert(“init”);});在第一次ajax调用后停止警报。我想这可能和我的问题有关 试试这个:
$(document).on( "pagebeforechange", function( e, data ) {
console.log( e )
console.log( data )
});
这会在更改页面上发生任何事情之前触发。数据对象包含所有changePage参数,例如fromPage
,transition
检查什么是转换。其他遇到此转换的人。我的问题的原因是我反复使用同一个容器。我认为正在发生的是,我重新写入的内容太快,数据属性被覆盖
因此,我添加了第二个容器,一切都开始正常工作:)
简言之,不要试图转换到您的页面上的同一页。。derp它发生的真的很快吗?显示隐藏就是你看到的闪光吗?你使用的是正确的
?你用的是什么浏览器?JQM说,如果您的浏览器不支持css3d转换
,您只会得到fade
(请参阅。并且,您是否正在使用
,当您从主屏幕将应用程序加载到iOS上时,它会破坏AJAX。文档类型为html 5,我正在使用该元标记这会破坏AJAX?我尝试了日志事件,这是它的输出。我注意到它有一个传输,但“allowSamePageTransition为false。我不确定该参数的作用,也不确定这是否是问题所在。allowSamePageTransition:false changeHash:true fromHashChange:false fromPage:[div#loadedpage.ui page]link:[a.navlink#loadedpage]pageContainer:[body.ui mobile viewport]反向:false showLoadMsg:true转换:“翻转”我还注意到我的fromPage和toPage在同一个位置。这很有意义,因为我只是在更改容器的内容,但也许我应该使用不同的容器来处理所有事情?现在每个ajax响应都会重写其中的内容。你知道……我只是有一个想法……也许我正在清理容器,然后它才有机会重新启动d里面有什么?天哪!哈哈,就是这样..在JQM有机会阅读之前,我正在清除div的内容。我感觉自己像个傻瓜。一旦我设置了第二个容器,转换就开始完美工作..哈哈,所以解决方案是:不要反复使用同一个容器。好的。很高兴它成功了。请检查我的答案,如果它能帮助你找到e解决方案!不客气!作为旁注:您还可以将allowSamePageTransition
设置为true,这是我有时在需要重新加载包含更改内容的页面时所做的操作。但最好不要触碰您的页面,因为它不起作用:-)
function makeHeader(){
return "<div id='menubar' data-position='fixed' data-role='header' data-tap-toggle='false'>
<table width='100%' cellspacing='0px' cellpadding='0px' border='0px'>
<tr><td width='12%'>
<a href='#home' data-transition='flip'>
<img src='/images/menu_button.png'>
</a>
</td>
<td width='90%'>
<img src='/images/menu_bar.png'>
</td>
</tr>
</table>
</div>";
}
function specialsetContent(command,value,url,target,effect){
$.ajax({
url: url,
type: "post",
data: 'value='+value+'&command='+command,
beforeSend: function() {
$.mobile.loading('show');
},
success: function(response, textStatus, jqXHR){
console.log("sucess");
replaceHtml(target,response);
},
error: function(jqXHR, textStatus, errorThrown){
console.log("error occured:"+textStatus, errorThrown);
},
complete: function(){
$.mobile.loading('hide'); //;
$.mobile.changePage(target,{transition:effect});
}
});
}
$(document).on( "pagebeforechange", function( e, data ) {
console.log( e )
console.log( data )
});
<div id="loadedpage" class="ui-page" data-theme="none" data-role="page" data-url="loadedpage"></div>
<div id="loadedpage1" class="ui-page" data-theme="none" data-role="page" data-url="loadedpage1"></div>