Friday 15 July 2011

javascript - Passing the page name by clicking on the page -



javascript - Passing the page name by clicking on the page -

i create web mobile app jquery mobile in static html, need take things(title, texts, images, etc) original wordpress site, when update wordpress, mobile app update too.

i'm using json api plugin. plugins transform pages json.

now, need create function pull json's ajax request, , part of logic this.

i started now, , created function in web app called getpages

function getpages(pagename) { var url = 'http://mywebsite.com/' + pagename + '/?json=1'; $.ajax({ url: url; etc etc etc }) }

i have several pages in mobile web (same wordpress), about, contact, partners, etc..

i need pass name of page function, function pull info page want.

for example:

i click on page in mobile app, var url this:

var url = 'http://mywebsite.com/' + pagename + '/?json=1'; var url = 'http://mywebsite.com/about/?json=1';

this how construction page looks in jquery mobile:

<div data-role="page" id="main" data-url="main" class="page"> <div data-role="header" data-theme="b" data-fullscreen="true"> </div> <div data-role="content" class="content"> </div> <div data-role="footer" class="footer" data-position="fixed" data-theme="b"> </div> </div> <!-- end page 1 -->

if observe, there data-url attr, attr define url. taking advantage of guys, there improve way create code above?

i have 1 code similar of pages, 1 main, 1 about, 1 contact, etc.. think not dry. right?

update

the question is:

is there way pass name of page clicked on web app (the same name of wordpress page) variable called pagename, in function?

when click here:

<li><a href="#about" data-rel="close">about?</a></li>

will load part:

<div data-role="page" id="about" data-url="about" class="page"> </div> <div data-role="header" data-theme="b" data-fullscreen="true"> </div> <div data-role="content" class="content"> <h2>about us</h2> <div class="video-container"> </div> </div> <div data-role="footer" class="footer" data-position="fixed" data-theme="b"> </div> </div> <!-- end page 2 -->

i need pull info of wordpress site using ajax, have:

function getpages() { var pagename = ""; var url = 'http://mywebsite.com/' + pagename + '/?json=1'; <- query json api create. $.ajax({ url: url; datatype: 'jsonp', }) }

so, when click in page, function create ajax request url in wordpress site, display content of wordpress page in mobile web app (i create part after solve problem)..

javascript php jquery json wordpress

No comments:

Post a Comment