3

I am using PhoneGap (Cordova-1.5.0.js) and I am running into this issue:-

I have a status page which shows multiple records(after firing an ajax call). When I click on any one record, it goes to the details page where it fires an ajax call to get the details of the record and displays it.

The funny thing is, If I go back to the status page(using navigator.app.backHistory()) and select some other record to see its details, it again goes to the details page BUT THIS TIME IT DOESNT FIRE THE AJAX CALL. It also doesnt fire the onDeviceReady() method.

For navigation from status page to details page, I use following on the onClick event of the div which I click:-

window.location="record_detail.html?userid=" + userID;

Oh and btw, I am using iScroll 4 as well. All used to work fine earlier and these problems cropped up after i included iScroll 4 in my project.

Thanks in advance.

  • Why is it that when I go back and forth between status and details pages more than 2-3 times, the onDeviceReady() method doesnt get called at all (ONLY in the details page)? Any help would be appreciated. – Vibhas Zanpure Mar 30 '12 at 09:30

1 Answers1

1

onDeviceReady is only supposed to fire once - when the first page is loaded and the PhoneGap framework is initialised.

If you want to do something every time a page is loaded use the appropriate Javascript load event.

EDIT

You should not use window.location, instead you should use navigator.app.loadUrl('');

This will make sure PhoneGap is not loaded every time you navigate to a new page. Loading it is time consuming and should only be done once for an app.

codemonkey
  • 5,257
  • 2
  • 18
  • 16
  • so If I have to fire ajax call every time a page is loaded/reloaded, I would have to put it in say, onLoad event ? Could you please give a code sample ? Thanks a lot :) – Vibhas Zanpure Mar 30 '12 at 12:25
  • And If what you said is true, then how come the onDeviceReady() method and the ajax call inside the status page gets fired no matter how many times i reload it ? Why only it doesn't get called from details page ? – Vibhas Zanpure Mar 30 '12 at 12:55