acces an array with JSON data retrived from AJAX request

Discussion and feedback on Construct 2

Post » Thu Jun 05, 2014 4:49 pm

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?
Thanks!
B
5
S
1
Posts: 13
Reputation: 415

Post » Thu Jun 05, 2014 5:29 pm

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?
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 05, 2014 7:48 pm

oh the array is predefined...
B
5
S
1
Posts: 13
Reputation: 415

Post » Sun Oct 12, 2014 10:07 pm

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:

Code: Select all
header('Content-Type: application/json');
   $output = array(
      'c2array' => true,
      'error' => false,
      'userID' => $ID
   );
   echo json_encode($output);


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.
You do not have the required permissions to view the files attached to this post.
B
9
S
1
Posts: 33
Reputation: 612


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 14 guests