acces an array with JSON data retrived from AJAX request

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi guys

    It's my first post here... I have a weird problem with my project...

    so: I loaded some data into an array, and it's there, no problem so far. The strange thing though is that I can't access the array when I'm inside a function. I can't set some text equals to one of the values in the array, if I try it returns "0", as if the array was empty...

    do you guys have any seggestions?


  • With out a capx I can only speculate but I found that if I "Create" an array/dictionary at the same time i load data to it and on the same cycle attempt to then access it from a function or any where else out side of where it was create the data is not there but if I wait 1 tick then the array/dictionary becomes globally usable. Is the array predefined or are you creating it at the time the you load data into it?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • oh the array is predefined...

  • I am having a similar issue. I'm not sure how to convert an AJAX request into an array and pull the data from it. I want simple name value pairs, so I assume I want a 2D array. The file that the AJAX request is sent to works fine when all I do is echo a single variable and set it to a variable in C2, but when I try echoing an array, such as:

    header('Content-Type: application/json');
    	$output = array(
    		'c2array' => true,
    		'error' => false,
    		'userID' => $ID
    	echo json_encode($output);[/code:fr0da6hw]
    and capturing it in C2 with AJAX On "tagname" completed -> Array Load from JSON string AJAX.LastData, I get tripped up. I assume that I'm either not loading it to an array in C2 properly, not setting up my array in C2 properly, or I just don't know how to pull the data from the C2 array properly.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)