Wednesday, 14 August 2013

Introducing HTML /DOM method in an array using AJAX/PHP

Introducing HTML /DOM method in an array using AJAX/PHP

I have a function that creates an array that contains the return value
from the HTML DOM method : window.document.getElementById()
function makearray1(){
array1=[1,window.document.getElementById('divID'),['a','b'],[1,2]];
}
then I pass the array into another function
use(array1)
function use(xxx){
xxx[1].innerHTML=xxx[2][0];
}
and 'a' is written in the appropriate div



later I decided to put the array in a form and post it to a txt file on
the server using php and:
JSON.stringify(array)



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.
so my php is basically this:
$a1='use(';
$data1 =file_get_contents("text_file.txt") ;
$a2=')';
echo $a1.$data1.$a2;
and the response text:
var n= XMLHttpRequestObject.responseText;
eval(n);
which pretty much means this:
use(text_file)
function use(xxx){
xxx[1].innerHTML=xxx[2][0];
}



the problem is that the array in the text file looks like this:
[1,null,['a','b'],[1,2]]
instead of:
[1,window.document.getElementById('divID'),['a','b'],[1,2]]



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?

No comments:

Post a Comment