Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i would prefer JS (JSON), because you have a native JSON Parser onboard and you can easy test it. You can use any other format with XHR (XMLHttpRequest/Ajax). You could also use XHR on local files (<a href="http://forums.mozillazine.org/viewtopic.php?f=25&amp;p=6033635" rel="nofollow">http://forums.mozillazine.org/viewtopic.php?f=25&amp;p=6033635</a>).</p> <p>This is a Example Class <code>LevelLoader</code> that loads JSON over XHR.</p> <pre><code>if ( typeof gamens== 'undefined') { var gamens= {}; } gamens.LevelLoader = function() { this.leveldata = {}; }; gamens.LevelLoader.prototype = { fromString : function(data) { this.leveldata = JSON.parse(data); // this.repaint(); }, fromFile : function(name) { var xmlhttp = xhr(); xmlhttp.open("GET", "level/" + name + ".js", true); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { this.fromString(xmlhttp.responseText); } } xmlhttp.send(null); } }; var loader = new gamens.LevelLoader(); // load "level/test.js" // example: // {"tiles":[0,1,1]} loader.fromFile("test"); console.log(loader.leveldata); </code></pre> <p>The xhr function that returns an XMLHttpRequest Object:</p> <pre><code>var xhr = function() { var _xhr = false; if (window.ActiveXObject) { try { _xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { _xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (ex) { _xhr = false; } } } if (!_xhr &amp;&amp; typeof XMLHttpRequest != 'undefined') { try { _xhr = new XMLHttpRequest(); } catch (e) { _xhr = false; } } if (!_xhr &amp;&amp; window.createRequest) { try { _xhr = window.createRequest(); } catch (e) { _xhr = false; } } return _xhr; }; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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