Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThanks for the help Guy. Previously, I did have the script declared in the head tag; but, I dropped it down by the code so I could easily associate the two for clarity - it did not seem to affect how the code loaded. I have now moved the script and code up to the head. Re: the window.onload function - I have included this line but the 'end callback' and 'end window onlioad function' brackets are throwing errors. Are these needed? Or, am I duplicating the existing YUI().use brackets? This line is concerning as it is not referenced in the Fiddle: Y.io('js/json-convert-values-response.json',{
      singulars
    2. CO@DaniB There was a small but significant mistake in my code. The closing parenthesis should have been to close the `use()` method but I had put it on the wrong line. I have corrected the code above now so that it shouldn't throw an error (look out for the comment which says `UPDATED`-- that's where the parenthesis has moved to). Hope that makes sense and works for you now. Let me know how you get on.
      singulars
    3. COFirstly, thanks again for your help. I am really struggling to place the 'end callback' and 'end window onlioad function' brackets into the correct place - I understand why they are needed; but, I'm a beginner so it would be great if you could be specific as I am just getting more errors. That said I have just cleared any further unnecessary links to CSS and JS out of the code. I am linked to the YUI combo JS and CSS and Firefox is NOW returning 'NO' errors - but the app won't run! Argh! Until you reply about the brackets I am going to look at what the 'try/ catch' is set to catch! Thanks
      singulars
 

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