weixin_33738555 2017-05-29 14:12 采纳率: 0%
浏览 85

在Ajax中保存JS数据

My current code is:

Play.save = function() {

    //Hide the buttons
    this.printButton.visible = false;
    this.saveButton.visible = false;
    this.backButton.visible = false;

    //Force the game to re-render.
    this.game.cameras.render(); //generally not recommended if you can help it

    //Get the canvas information
    var img = this.game.stage.canvas.toDataURL("image/octet-stream");

    this.saveajax(img);

    //Show UI again.
    this.printButton.visible = false;
    this.saveButton.visible = true;
    this.backButton.visible = true;

}

Play.saveajax = function(img){
    $.ajax
    ({
        url: "http://localhost/ourthing/character/save.php",
        type: "POST",
        cache: false,
        data: {
            img: img
        }
    });
}

The file 'save.php' works (when i simply open the file). It will execute a query which it has to do. Problem here is: with this script i want to update a user with the given post data (img). But it doesnt execute on this request.

(i create data for var img and send this data to the saveajax function, which will open save.php to execute the query).

Im very new to JS/ajax. Does anyone can help me?

Best regards

  • 写回答

2条回答 默认 最新

  • elliott.david 2017-05-29 14:23
    关注

    apparently I cant comment, so my question is what are you getting on save.php with command like

    error_log(print_r($_REQUEST,true));
    

    I suspect JSON issue here. can we see save.php? Ok didn't see your previous comment, scrap that - your Jquery is not included.

    评论

报告相同问题?