jquery - PageCreate on Refresh -
ok, new jquery mobile college assignment
im using ajax calls pull in data external cms. stands im using ajax call dynamically insert buttons homescreen , create , link relevant pages these buttons.... problem when refresh subpage eg qualifications automatically brings me home... have #home.trigger(pagecreate) within ajax call otherwise buttons wouldn't render proper buttons instead of links...
i presume on refresh of subpage whole index.html refreshed , therefore pagecreate triggered again...bringing me home...but url still pointing #qualifications... if navigate section of app, , hit button (data-rel="back") attempts return me #qualifications page though last page displayed homepage... , ends rendering no page @ all....
how might set function catch refresh... navigate previous page (from browser history) , pagecreate correct page...?
my apologies if question convoluted... first time posting! , technically im meant graphics guys on project... :)
overall im attempting use ajax calls dynamically build whole site...
var nextpage[] being used create url ajax calls next level down in cms... smarter way?
$.ajax( { url: "http://myurl/api/list", type: 'get', datatype: 'jsonp', success: function(data) { if(data.result == 'success') { var homepage=$('<div id="home" data-role="page" data-title="myguide : home" data-theme="b">' +'<div data-role="header" data-position="fixed">' +'<h1>home</h1></div>' +'<div id="logo">' +'<img src="images/iiiguide_logo.png"/></div>'); homepage.appendto($.mobile.pagecontainer); $.mobile.changepage( homepage ); var pages=[]; var nextpage=[]; $.each(data.data,function(key,val) { var homebuttons=['<a href="#'+ val.label.replace(/\s/g, "") +'" data-role="button" data-icon="arrow-r"' +'data-iconpos="right">'+val.label+'</a>']; $('#home').append(homebuttons); var pages=$('<div id="'+ val.label.replace(/\s/g, "") + '"' +'data-role="page" data-title="myguide :'+val.label.replace(/\s/g, "") + '" data-theme="b">' +'<div data-role="header" data-position="fixed">' +'<a href="#home" data-icon="home">home</a>' +'<a href="#" data-icon="back" data-rel="back" >back</a>' +'<h1>'+ val.label.replace(/\s/g, "") +'</h1></div>' +'<div id="logo">' +'<img src="images/iiiguide_logo.png"/></div></div>'); pages.appendto($.mobile.pagecontainer); nextpage.push('http://myurl/api/list?category_id='+val.id); }); $('#home').trigger("pagecreate"); } } });
Comments
Post a Comment