0 Favourites

How do I load json from ajax request

  • i am currently using the xml plugin to load my variables when using ajax requests and it works fine but but the xml data is much larger in size so since im aiming for the mobile market i want to minimize the data transfer size.ad having a json plugin that works exactly like the xml plugin would help to minimize the data size.

    is there a json plugin for this?

  • or is there maybe a usable workaround?

  • Ashley: you wrote earlier that this feature was planned but no ETA, do you have an update on this task?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • bump

  • Try this...

    https : // www scirra com /forum/plugin-json-import-export-generate-edit-inspect_t100042

  • thanks, tried but this plugin loads json from an external file, i need to parse the Json data from AJax.lastdata

  • kaiko I created a plugin for personal use that might help you? Its a 3 dimensional associative array object (accessed via field name instead of indexed integer values). It can feel complicated at first but It supports loading raw JSON strings right into and easily accessing the data inside it which is what your looking for. I had the same issue as you but couldn't find a plugin I liked so i created this. I don't officially support it but its nothing more than a wrapper to access a 3 dimensional JavaScript variable for named storage purposes and perfectly stable. I use it in all my projects ..I attached the plugin and an example capx below if your interested?

    Plugin

    [attachment=1:1r0thvj6][/attachment:1r0thvj6]

    Example capx usage r195

    [attachment=2:1r0thvj6][/attachment:1r0thvj6]

    [attachment=0:1r0thvj6][/attachment:1r0thvj6]

  • uhm ok, i tried your plugin,but in your example I cannot see how you acquire external data?

    from an ajax request the complete dataset is in ajax.lastdata and i neeed to get it into some form of function so i can assign its values to variables see pic below.

  • kaiko you can take the Ajax.LastData and load it into the Storage object using the Merge Table action. When you're done you can dump the JSON string to text object to see it.

    [attachment=0:885qwrwc][/attachment:885qwrwc]

    The storage object is 3 dimensional so if your JSON object is one dimensional it will create top level names of "default".

    Example

    Storage.Get("default","default","myfield")

    Think of it as a C2 Array that works more like a C2 Dictionary

  • ive tried this but storage doesnt print anything in text ,and when i debug i cant see that storage gets any data at all.

    can you see where what im doing wrong?

  • kaiko Yah.. I see two problems..

    1) You defined the tag for the AJAX request as "get login". But on the event listener you are looking for on "login".. those key names have to be the same or your event listener wont detect when the AJAX response comes back.

    2) Your domain does not appear to allow cross domain AJAX requests. IE the AJAX request is originating from "http://YourTestIP:50000" but its being sent to "http://dev.canvaramanager.com". You need to allow crosss domain AJAX requests by adding a PHP header tag or the AJAX request is blocked by your server. This is standard as it is meant to protect the server from outside attacks.

    You need to add this to your PHP file. Caution this is dangerous as it opens up to potential malicious attacks from out side domains but is needed for testing

    header('Access-Control-Allow-Origin: *');
    [/code:io47tqq6]
  • troublesum:how to debug your plugin?

  • troublesum: never mind i got it working now, thanks your plugin rocks.

  • kaiko .. Awesome!! ... Glad it worked for you.

    Yah the debug feature needs to be enabled. I did that because sometimes the storage can be pretty large so you can enable to view the whole thing in the debug view or just a certain table or list.

    To enable it, call one of these action on start of layout.

    [attachment=0:3tigthfm][/attachment:3tigthfm]

    Let me know if you have any questions

  • troublesum: how can we get your plugin to be part of C2 default package?

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