Jump to content

get variable from mysql using ajax


nezarabd
 Share

Recommended Posts

i want to get some data from mysql to use in phaser.io game
i try this in start of game.js
the ajax work fine but after the game.js end
how make it work first when the game.js
   

    
      value = 1;
      wher = "a = 1";
      var currentrec = [];
         $.ajax({
         url: 'validate.php',
         type: 'post',
         dataType: 'json',
         data: {'method': "get_unit_lesson", 
         'value': value,
         'wher': wher,
         'tbl': "geography_prep_3"},
         success: function (data) {
        currentrec = data;
        },
        });

    var dd = [];
    for (var s = 0; 0 < currentrec.length; s++) {
    dd = currentrec["unit"]}


    var game;

Link to comment
Share on other sites

The ajax call is asynchronous. You have to handle the promise callback

      value = 1;
      wher = "a = 1";
      var currentrec = [];
    function validate() {
         return $.ajax({
         url: 'validate.php',
         type: 'post',
         dataType: 'json',
         data: {'method': "get_unit_lesson", 
         'value': value,
         'wher': wher,
         'tbl': "geography_prep_3"},
         success: function (data) {
        currentrec = data;
        },
        });
    }

    var successful = validate();
    successful.done(function(){

        var dd = [];
        for (var s = 0; 0 < currentrec.length; s++) {
        dd = currentrec["unit"]}


        var game; 
    });

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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