Joanrufe
Joanrufe

Reputation: 85

Javascript code doesn't work on phonegap

I read at this link but there's not much discussion or info (of the questioner).

I'm writing and android app using phonegap in Eclipse development environment. It's very starter code... so simple that I don't understand why isn't working.

I have an index.html with this js function (jquery, jquery-mobile and cordova 2.9 are included) that takes json from remote server and append it to a jquery mobile list:

$(document).bind('deviceready', function() {
  $.getJSON("http://www.remote-server.com/json.php?return=list",function(json) {
    $.each(json,function(i,item){
      $("#list").append('<li><a href="details.html?id=' + item.id + '"><h2>'+item.title+'</h2><p>Start date:'+item.start+'</p></a></li>');
    });
    $("#list").listview('refresh');     
  });
});

Ok, until now all it's Ok. But when open details.html, can't execute any js code. At the beginning I thought It's was problem of includes or something but then I tried simple javascript code setting manually text's tags like: document.getElementById('title').value = "F!&k"

Do I miss something? config.xml It's standard starter code.

Upvotes: 1

Views: 868

Answers (1)

Th0rndike
Th0rndike

Reputation: 3436

Where is the javascript located?

If you need this javascript to be available at more than one page you should put it in the head of all of your pages.

If you need this javascript to be available only in a single page, then you should put the javascript inside the

<div data-role='page'>

that defines the jquery-mobile page where you need it.

This is because of the ajax navigation model of jquery mobile.

Hope it helps.

Upvotes: 2

Related Questions