【发布时间】:2017-05-29 14:12:32
【问题描述】:
我当前的代码是:
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”有效(当我打开文件时)。它将执行它必须执行的查询。这里的问题是:使用这个脚本,我想用给定的帖子数据(img)更新用户。但它不会按此请求执行。
(我为 var img 创建数据并将此数据发送到 saveajax 函数,该函数将打开 save.php 以执行查询)。
我对 JS/ajax 很陌生。有谁能帮帮我吗?
最好的问候
【问题讨论】:
-
您的控制台(F12 -> 控制台选项卡)是否有任何错误?
-
是的,未捕获的 ReferenceError:$ 未在 State.Play.save (dressup-1.0.0.js:474) 的 State.Play.saveajax (dressup-1.0.0.js:502) 中定义) 在 State.Play.checkInputs (dressup-1.0.0.js:495) 在 SignalBinding.execute (kiwi.js:5397) 在 Signal.dispatch (kiwi.js:5289) 在 InputManager._onUpEvent (kiwi.js:18273) ) 在 SignalBinding.execute (kiwi.js:5397) 在 Signal.dispatch (kiwi.js:5289) 在 Mouse.onMouseUp (kiwi.js:18713) 在 HTMLDivElement.
(kiwi.js:18636)。它重定向到我创建的 saveajax 函数。 -
那通常是指不导入jQuery,你是在导入吗?
-
很简单,你的 jquery 库没有被包含进来。检查 Network 选项卡以获取 JS 引用。并仔细检查 lib 的 url。
-
哦,我现在感觉很糟糕。很多很多谢谢!现在可以了。多么愚蠢的失败。我真的很高兴你的两个答案这么快!祝你有美好的一天:)
标签: javascript php ajax