Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I escape the parsed data from an XHR function?
    primarykey
    data
    text
    <p>My question is essentially that I am trying to make a universal Ajax function solely for retrieving information which will be parsed and then automatically stored as the value of whatever called it. In this specific case it is a giant dictionary word-list for a hangman game I am making. How can I escape the Array that is created by <code>ajaxRequest.responseText.split("\n")</code> into whatever calls it. In my case it will be <code>ALAMI.Hangman.Wordlist</code></p> <p><strong>My end goal is to be able to use <code>ALAMI.Hangman.Wordlist[i]</code> and have it return the value of whatever string is stored at that place in the Array.</strong></p> <p>Before you freak out this isn't all of my code the XHR request function is called through <code>ALAMI.XHR();</code> as written below but I didn't include it in this code because I felt it was unnecessary. </p> <pre><code>ALAMI.XHR.Get = function(URL){ "use strict"; var ajaxRequest = ALAMI.XHR(); var ajaxResponse; ajaxRequest.open("GET", URL, true); ajaxRequest.send(null); ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState === 4){ ajaxResponse = ajaxRequest.responseText.split("\n"); var extensionLocation = URL.lastIndexOf('.'); console.log(URL.substr(extensionLocation) + " file ...... " + ajaxResponse.length + " lines."); } } return ajaxResponse; } ALAMI.Hangman = ALAMI.Hangman || {}; ALAMI.Hangman.Wordlist = ALAMI.XHR.Get('fulldictionary.txt'); //I want ALAMI.Hangman.Wordlist to be equal to the Array of ajaxRequest.responseText.split("\n") </code></pre> <p><strong>My end goal is to be able to use <code>ALAMI.Hangman.Wordlist[i]</code> and have it return the value of whatever string is stored at that place in the Array.</strong></p> <p>Also I'm trying to make my ajax function a universal method that I can use an infinite number of times. for example: </p> <pre><code> ALAMI.Hangman.Wordlist1 = ALAMI.XHR.Get('fulldictionary.txt'); ALAMI.Hangman.Wordlist2 = ALAMI.XHR.Get('dictionary2.txt'); </code></pre> <p>The end goal is:</p> <p>If in the global space I write <code>console.log(ALAMI.Hangman.Wordlist[0]);</code> it currently shows up as undefined, however, what I want is for the array to have been stored in <code>ALAMI.Hangman.Wordlist</code> so that when I do that it will ouput the first value of the array.</p> <p><code>console.log(ALAMI.Hangman.Wordlist[0]); //Should output Apple</code></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.
 

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