Note that there are some explanatory texts on larger screens.

plurals
  1. POReplicating preloaded HTML /DOM method results in an array using AJAX/PHP
    primarykey
    data
    text
    <p>I have a function that creates an array that contains the return value from the HTML DOM method : window.document.getElementById()</p> <pre><code>function makearray1(){ var array1=[1,window.document.getElementById('divID'),['a','b'],[1,2]]; } </code></pre> <p>then I pass the array into another function</p> <pre><code>use(array1) function use(xxx){ xxx[1].innerHTML=xxx[2][0]; } </code></pre> <p>and 'a' is written in the appropriate div</p> <hr> <p>later I decided to put the array in a form and post it to a txt file on the server using php and:</p> <pre><code>JSON.stringify(array) </code></pre> <hr> <p>So now I use AJAX to call the data from the txt file after the rest of the page has loaded etc... and the original function used to make the array is not included at all. </p> <p>so my php is basically this:</p> <pre><code> $a1='use('; $data1 =file_get_contents("text_file.txt") ; $a2=')'; echo $a1.$data1.$a2; </code></pre> <p>and the response text:</p> <pre><code> var n= XMLHttpRequestObject.responseText; eval(n); </code></pre> <p>which pretty much means this:</p> <pre><code> use(text_file) function use(xxx){ xxx[1].innerHTML=xxx[2][0]; } </code></pre> <hr> <p>the problem is that the array in the text file looks like this:</p> <pre><code> [1,null,['a','b'],[1,2]] </code></pre> <p>instead of:</p> <pre><code> [1,window.document.getElementById('divID'),['a','b'],[1,2]] </code></pre> <hr> <p>My question: Is there any way that I can do the equivalent of what I'm trying to do here, which is immediately replicate the return value of the HTML/DOM method in an array using AJAX/php?</p> <p>To clarify: this is a simple example. I actually have a huge, multidimensional array that already has established pointers, or prefetched DOM nodes in it. Now I'm trying to replicate the array when a text version is loaded using ajax. I'm looking for a recursive approach to changing all of the null assignments with something that will immediately fetch the appropriate DOM node. Most likely I will need to do it with the response text, but was hoping I could do it with the php portion. </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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