Click here to Skip to main content
15,911,707 members

Comments by ilhomelv (Top 7 by date)

ilhomelv 2-Feb-18 2:38am View    
added a gloal page variable, and a page increment on every call, trying to pass that param thru Get to PHP, now stuck there in PHP

Hide   Copy Code
var page="";var btn = document.getElementById("button");//create an event listener and on click get function to load json data from json filebtn.addEventListener("click", function() {	var xreq = new XMLHttpRequest();	var response = document.getElementById("videoObjs");	xreq.open('GET', 'xjsonData.php?page='+page, true);	xreq.onload = function() {		response.innerHTML += xreq.responseText;  //.php echo saved prints on here		console.log(response);	};	xreq.send(null);	page++; console.log('page '+page);});

$page = $_GET['page'];
$file = "data.txt";
$content = file_get_contents($file);  //gets json data content
$arr =json_decode($content, true); //converts json to php associative array
print_r($arr);
echo "<br><br>";
echo "page: ".$page;
echo "<br><br>";
echo "count: ".count($arr);
echo "<br><br>";

ilhomelv 30-Jan-18 13:53pm View    
thanks, i will rethink and i got solution, simply by a callback(jsondata) this works ))
but i was thinking of assigning the var to global var soomehow may be
ilhomelv 28-Jan-18 17:11pm View    
can u pls show me any online link with an example, let me see how they coded there, i spent almost 40hours now, cant solve this problem, i did solve with passing the var inside function call as parameter, however id like to have it accessible as globbally as a property not a parameter inside call method.
ilhomelv 28-Jan-18 17:08pm View    
the array is saved on file in one long line, how to save the array in the file in separate lines, instead of having one long line of arrays. thank u
ilhomelv 28-Jan-18 6:55am View    
i passed it inside call() and that works, but when im trying to assign it to a globally declared variable it keeps printing undefined, i did checked about hoisting, may be variable is hoisted, ((((