1

I'm trying my hand at developing an app for Blackberry Playbook (Yes, I know, it's dead.. bear with me).

I'm using a simple WebWorks app and my jQuery ready() function appears to be called twice when I load my page.

<!doctype html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                    alert("ready");
            });
        </script>
    </head>
    <body>
        Hello World.
    </body>
</html>

Any idea why this would happen? I'm testing in the Ripple simulator for Playbook.

Simon
  • 521
  • 2
  • 9
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229
  • so when you reload the page alert is fired twice? – Kishore Jan 07 '12 at 22:28
  • This situation happens using the shortform syntax as well. In another place someone suggested setTimeout(startup, 3000) [where startup is a wrapper function around the normal ready call]. Which does work, but is a terrible workaround and must be removed for production. (where this problem does not happen) I'm still looking for a better solution...Will update here. – Simon Feb 27 '12 at 15:37

2 Answers2

1

I am pretty sure that the current version of Ripple, on Windows anyway, loads the page twice. It has nothing to do with jQuery (or CoffeScript which I am also using).

The solution I have that works, even if I don't like it is:

// earlier
var runner = function() {
  alert('ready');
};

// later
$(function() {
  if(window.tinyHippos) {
    setTimeout(runner, 3000);
  } else {
    runner();
  }
});

Pretty hacky, but it seems to work. Hopefully in Ripple's next iteration the double-load will go away.

Simon
  • 521
  • 2
  • 9
0

In your testing efforts, have you attempted the shortcut alternative to using .ready() to see if they perform the same result with two alerts?

$(function() {
    alert('ready');
});

Also, maybe try using a previous version of jQuery only to test to verify if it's related to the problem in the latest version of jQuery.

So, maybe try 1.6.1 instead of 1.7.1.

I wish I could help more, but I don't personally own a Playbook, unfortunately.

Ryan
  • 3,475
  • 2
  • 16
  • 12