Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Bergi says in the comments above, it looks like the script did not load or execute early enough.</p> <p><strong>ONE POSSIBLE SOLUTION...</strong></p> <p>To make sure it is, you should declare the YUI script tag in the head of your HTML. Try that first to see if it solves your problem. However...</p> <p>...</p> <p><strong>WAITING UNTIL READY</strong></p> <p>You should put your other code in the head too, but specify it so that it only loads when the whole document has loaded.</p> <p>The simplest way to do this would be:</p> <pre><code>window.onload = function () { // what to do when window has loaded YUI().use("node", "io", "json-parse",function (Y) { // ... the code in your callback function, as provided above ... }); // end callback -- UPDATED }; // end window onload function </code></pre> <p>YUI has its own way of handling code that should when the document is ready...</p> <pre><code>YAHOO.util.Event.onDOMReady </code></pre> <p>But as your problem is with <code>YUI</code> not being defined, I'm not sure this will help.</p> <p>...</p> <p><strong>CHECKS AND SAFEGUARDS PATTERN?</strong></p> <p>A more sophisticated pattern could involve setting an intermittent check to see if <code>YUI</code> is defined and then cancelling the check once it is and executing the code you need. That would use a method called <code>setInterval()</code> and look something like this:</p> <pre><code>var checkYUI = setInterval(function() { // create a function to be executed within the interval and assign the interval to a global variable if (YUI) { // check the global variable `YUI` exists clearInterval(checkYUI); // cancel the interval check YUI().use("node", "io", "json-parse",function (Y) { // now we know `YUI` exists call its `use()` method // ... the code in your callback function, as provided above ... } } }, 100); // checks every 100 ms </code></pre> <p>You could make the checking more complicated still by, for example, checking that <code>YUI</code> is an object, that it has a <code>use()</code> method, etc. But hopefully this will suffice to show how it could work.</p> <p>I'm not sure what you did in your previous trials that made them succeed whilst this one failed but it might be worth studying them to see if such checks/safeguards are already in place.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload