Jump to content

load json from server with ajax


mrsnow
 Share

Recommended Posts

Hi everyone 

 

i need a bit help with this and phaser what is the best way to load a json data from a  server with jquery ajax, can i use jquery with phaser? can i use a ajax call like a webapp for example

 

$.ajax({

     type: GET,POST ETC,

     url: somewhere,

     data:some data,

     callback function.......

 

})

 

or exist another way to do this . This is my first time with phaser and i am developing a game with this features:

 

1) i have a main view with a image logo

2) this second view is sign up form (i need send a json to the server) 

3) the third view is for instructions and has the start game buttom

4) the next view is the first level

5) this view is after finish the level in this view we have a question (i need to do a get request to load questions and answers from the server and then send  a POST request the answer to the server again)

Link to comment
Share on other sites

  • 1 year later...

Of cource you can add .json file and use jquery for these matters. One neat trick you can do is to declare your json object as a variable.

var jsonObj = {};

And have this file declared as a .js file which you can load in a script tag.

<script type="text/javascript" src="myJSON.js"></script>

This way you can load json objects even in sandboxed environments like Codepen or other sites.

 

I used this technique in my example: http://nightlycoding.com/index.php/2015/01/phaser-io-how-to-use-atlashash-to-your-advantage/#more-645

 

to load the json for the sprite animations.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...