我目前的代码是:
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
}
});
}该文件'save.php‘工作(当我只是打开文件)。它将执行它必须执行的查询。这里的问题是:使用这个脚本,我想用给定的post数据(img)更新用户。但是它不执行这个请求。
(我为var img创建数据并将这些数据发送给saveajax函数,该函数将打开save.php以执行查询)。
我对JS/ajax非常陌生。有人能帮我吗?
诚挚的问候
发布于 2017-05-29 14:41:05
答案:
我必须包括jQuery:
<script src="assets/js/jquery.js" ></script >谢谢@Don‘’tVoteMeDown和Lixus
Save.php文件:
$db = framework::getDBO();
$data = array(
'canvas_character' => $_POST['img'],
);
$db->where('id', 1);
$db->update('ot_users', $data);(我使用自己的框架)
发布于 2017-05-29 14:23:40
显然我不能对此发表评论,所以我的问题是,你在save.php上有什么命令,比如
error_log(print_r($_REQUEST,true));我怀疑这是JSON的问题。我们能看看save.php吗?Ok没有看到您以前的评论,请放弃-您的Jquery不包括在内。
https://stackoverflow.com/questions/44244602
复制相似问题