Fairly new to jquery mobile and new to parsing json - have done much research to no avail. Have tried 10sec delay in settimeout function
My app works correctly on my samsung galaxy s2 but on my samsung galaxy tablet 10.1 it does the following.
Using latest jquery 1.2.0
and jquery-1.7.2
I call getlocations2.php
and if i return four items or less the collapsible set opens and closes correctly. If i return 5 or more items :
- i click on the top collapsible to expand it - nothing happens
- i click on second collapsible h3 and it opens first collapsible
- after that it can get random re expanding h3's but usually it is the last h3 that was touched and failed to open.
- it can work correctly for a short while.
Thanks for any tips:
Code :
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>';
}
;
on line 12 & 40. I'd start by fixing that. It's preferable to use the x+=
y operator instead of x = x + y, to avoid bad code sneaking in with typos. I put these fixes in this JSFiddle: jsfiddle.net/ubLyoc99/2 There hasn't been any activity on this for a long time I suggest OP gives an update or an admin closes this question. – Yoakum