Ajax jquery mobile可折叠和galaxy选项卡10.1 json响应提供随机响应
对于jquerymobile和解析json来说都是新手,他们做了大量的研究,但都无济于事。 已尝试设置超时功能延迟10秒 我的应用程序在我的三星galaxy s2上正常工作,但在我的三星galaxy平板电脑10.1上,它执行以下操作 使用最新的Ajax jquery mobile可折叠和galaxy选项卡10.1 json响应提供随机响应,ajax,json,jquery,jquery-mobile,collapsable,Ajax,Json,Jquery,Jquery Mobile,Collapsable,对于jquerymobile和解析json来说都是新手,他们做了大量的研究,但都无济于事。 已尝试设置超时功能延迟10秒 我的应用程序在我的三星galaxy s2上正常工作,但在我的三星galaxy平板电脑10.1上,它执行以下操作 使用最新的jquery 1.2.0和jquery-1.7.2 我调用getlocations2.php,如果我返回四项或更少,可折叠集将正确打开和关闭。如果我返回5个或更多项目: 我点击顶部的可折叠展开它-什么也没发生 我点击第二个可折叠h3,它会打开第一个可折叠h
jquery 1.2.0
和jquery-1.7.2
我调用getlocations2.php
,如果我返回四项或更少,可折叠集将正确打开和关闭。如果我返回5个或更多项目:
function doajax2($vurl,$vdata,$vtype,$vfrom){
$.ajax({
url: $vurl,
dataType: 'json',
data:$vdata,
async: false,
success: function(rtndata) {
$.mobile.hidePageLoadingMsg(); //alert(result.toSource())
rtndata2=(JSON.stringify(rtndata, null, 4));
rtndata2=rtndata2.substring(13);
rtndata2=rtndata2.slice(0, -2)
var res = eval(rtndata2);
$('.displaylocations').html('');
g_html=res[0].brand;
if (res[0].id> -1){
g_html=g_html+'<div data-role="collapsible-set" data-theme="f" >';
for (var i=0;i<res.length;i++){
//for (var i=0;i<6;i++){
lochtml('loc',i,res[i].locid,res[i].loccode1,res[i].head,res[i].desc,res[i].lang,res[i].lat1,res[i].long1,res[i].img1,res[i].limit);
}
g_html=g_html+'</div>';
}
console.log('g_html'+g_html);
$('.displaylocations').css('display','none');
$(".displaylocations").html(g_html);
// $(".displaylocations").html(str);
setTimeout(function(){ //make sure displaylocations has been updated
$('#lhead2').html('Tuhura <span lang="en">Locations</span>');
$('.displaylocations').trigger('create');
$('.displaylocations').css('display','block');
$( ".displaylocations" ).collapsibleset( "refresh" );
},300);
},
error: function(faildata){
switch ($vfrom) {
case "region" : $("#lhead3").html('Region Info Unavailable...');break
case "locs" : $("#lhead2").html('Locations Unavailable...');break;
}
}
});
}
function lochtml($vtype,$vno,$locid,$loccode1,$head,$desc,$vlang,$vlat1,$vlong1,$img1,$limit) {
console.log('lochtml '+$desc);
g_html=g_html+ "<div class='locgoh'>";
g_html=g_html+ '<a href="#" onclick="getsitedetails('+"'gps','"+$locid+"','"+$loccode1+"','s','sites','"+$vlang+"',1,0,'x',"+$vlat1+","+$vlong1+')">';
g_html=g_html+ '<img src="http://tuhtop.co.nz/images/rightarrow.png" width="30px" height="30px" /></a>';
g_html=g_html+ '</div>';
g_html=g_html+'<div data-role="collapsible" class="loccollapse" data-theme="f" div="coldiv">';
g_html=g_html+ '<h3>'+$head+'</h3>';
g_html=g_html+ '<p><div class="locli0">';
g_html=g_html+ '<span class="li1">' +$desc+ '</span>';
g_html=g_html+ '<span class="li2"><a href="#" onclick="getsitedetails('+"'gps','"+$locid+"','"+$loccode1+"','s','sites','"+$vlang+"',1,0,'x',"+$vlat1+","+$vlong1+')">';
g_html=g_html+ '<img src=\''+$img1+'\' width=\'120"\' height=\'120\' alt=\''+$img1+'\'/></a>';
g_html=g_html+ '</span>';
g_html=g_html+ '</div></p>';
g_html=g_html+'<div class="clearfloat"></div>';
g_html=g_html+'</div>';
}
函数doajax2($vurl,$vdata,$vtype,$vfrom){
$.ajax({
url:$vurl,
数据类型:“json”,
数据:$vdata,
async:false,
成功:功能(rtndata){
$.mobile.hidePageLoadingMsg();//警报(result.toSource())
rtnda2=(JSON.stringify(rtnda,null,4));
rtnda2=rtnda2.子串(13);
rtnda2=rtnda2.slice(0,-2)
var res=评估值(rtndata2);
$('.displaylocations').html('');
g_html=res[0]。品牌;
如果(res[0].id>-1){
g_html=g_html+“”;
对于(var i=0;i如果我错了,请纠正我,就我在阅读代码时所知,可能存在多个问题
首先,引用g_html变量,为什么不在函数lochtml中返回html,然后在for循环中,像这样构建html,它更可读
for (var i=0;i<res.length;i++){
g_html=g_html+lochtml('loc',i,r...)
}
for(var i=0;当事情没有正确更新时,我为jQuery Mobile找到了两种“一网打尽”的解决方案,分别是$.Mobile.activePage.trigger('create')和$(parent div.trigger('updatelayout')。当我以这种方式得到结果时,我总是感觉有点不舒服,但这两种解决方案(特别是$.Mobile.activePage.trigger('create'))在不同的情况下解决了许多意外的问题。当您返回5个以上的项目时,您的“g_html”最终版本是否有效?具体来说,是否所有标记都正确关闭?这已经将近两年了,截至2014年6月10日,被评为Stackexchange上投票数第二高的未回答jQuery问题。这个问题已经解决了吗?我的g问题的背后是一些时髦的代码。第12行和第40行缺少了两个分号;
。我首先要解决这个问题。最好使用x+=
y操作符,而不是x=x+y,以避免错误代码和打字错误混入。我将这些修复放在这个JSFIDLE中:这方面已经有一段时间没有任何活动了很长一段时间我建议OP提供一个更新或者管理员关闭这个问题。
the res[0].brand above
<div data-role="collapsible-set" data-theme="f">
<div class='locgoh'>
<a ...>
<img />
</a>
</div>
<div data-role="collapsible" class="loccollapse" data-theme="f" div="coldiv">
<h3>...</h3>
<p>...</p>
<div class="clearfloat"></div>
</div>
...
...
</div>