How do I Get AJAX result into array

0 favourites
  • 3 posts
From the Asset Store
Array Editor
$1 USD
80% off
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi all,

    I will make it short.

    I have a AJAX action and get a result like: 1, 43, 492, lalala, example, 1455

    Or atleast, thats what i can do. I can make the , a | or whatever thats not the problem.

    All i need to know is how to get all these different results into seperate results and not in 1 sentence.

    So: 1, 43, 492

    Should become:

    Level = 1

    Experience = 43

    Coins = 492

    Let me know if my example is clear and any one has a solution!

    Thanks in advance!

  • Unfortunately Arrays in c2 are not associative.

    Hence I use the HashPlugin from Rexrainbow.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I used tokens, and it's fairly easy from there. You need a way to sort them on incoming though, so 3-4 values like that is easy: set 'level' to tokenat(ajax.lastdata,0,"|") for example.

    If you have bigger strings coming in, you will need to perhaps use some loops (token count times + loop index), or token-in-token (such as: level'1|experience'43 etc., with | as one token and ' as the other).

    Or, if you have all of that in an array, send the array data asJSON through ajax, then load it into an array with ajax last data. This way is harder to set up for a game in general, but easier to manage in large-scale games.

    Hope that helps!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)