Send Javascript value to PHP with Phaser framework -


i want send javascript variable php, , php store in database.

now when search on google, lot of information visible this. times see ajax, when use ajax code doesn't run. tried example http://www.tutorialspoint.com/ajax/ajax_database.htm , tried answers on stackoverflow.

maybe won't work because use phaser, framework. maybe i'm trying long , don't think anymore, need fresh @ this.

on phaser game have different prefabs. 1 called gameover.js , can have access score line of code:

var score = this.game_state.score; 

that's easy. ok, have send php. used jquery selector (jquery.post() , jquery.ajax()) , tutorial above, without success.

at moment have in javascript:

game.gameover.prototype.submitscore = function () {     var ajaxrequest;  // variable makes ajax possible!    try{        // opera 8.0+, firefox, safari       ajaxrequest = new xmlhttprequest();    }catch (e){        // internet explorer browsers       try{          ajaxrequest = new activexobject("msxml2.xmlhttp");       }catch (e) {           try{             ajaxrequest = new activexobject("microsoft.xmlhttp");          }catch (e){              // went wrong             alert("your browser broke!");             return false;          }       }    }     var score = this.game_state.score;    var querystring = "?score=" + score ;     ajaxrequest.open("get", "senddata.php" + querystring, true);    ajaxrequest.send(null);  } 

and in senddata.php

$score = $_get['score']; echo "score:" . $score; 

i guess last part isn't easy, can't figure out! can me.

if want send request page in jquery should able use following:

game.gameover.prototype.submitscore = function () {     $.ajax({         url: 'senddata.php?score=' + this.game_state.score     })     .done(function () {         console.log('done');     })     .fail(function () {         console.log('failed');     }); } 

this works expected jquery 2.2.0 , phaser 2.4.4.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -