我有简单的应用程序,我需要从 MySQL 获取数据。我读到我可以在 *.php 文件中使用服务器上的脚本来做到这一点,我需要做的就是从我的 qooxdoo 应用程序运行这个文件并获取打印数据。这是一段代码:
doWysyl.addListener("execute", function(e) //doWysyl is button
{
var req = new qx.io.remote.Request("http://localhost/db_connector.php", "GET", "application/json");
req.addListener("completed", function(e)
{
alert("Something");
});
req.send();
}, this);
db_connector.php 文件:
<?php
$db = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Can't connect: ' . mysql_error());
}
$result = mysql_query("SELECT Id FROM gitterbox WHERE Ukryj=0")
$dane = array();
while ($row = mysql_fetch_assoc($result)) {
$dane [] = $row["Id"];
}
mysql_close($link);
echo json_encode($dane);
?>
我的问题是 alert("Something"); 永远不会显示,就像完成的事件永远不会被触发一样。我也尝试过不同的事件,但没有任何帮助。我确定 db_connect.php 已打开,因为我已经检查过了。
好的,我编辑了我的代码以使用 Xhr 请求,现在它看起来像:
doWysyl.addListener("execute", function(e) {
var req = new qx.io.request.Xhr("http://localhost/db_connector.php", "GET");
req.addListener("success", function(e) {
alert("success");
}, this);
req.addListener("fail", function(e) {
var reqa = e.getTarget()
var response = req.getResponse()
alert("fail "+response+". Code: "+reqa.getStatus())
}, this);
req.send();
}, this);
但问题是我总是会触发失败事件,并且在警报中我有消息:
fail null. Code 0
我在警报之前添加了断点,这就是堆栈跟踪(使用 Chrome 和 Windows 7 x64):
(anonymous function) (class/custom/MainWindow.js:27)
qx.Class.define.members.dispatchEvent (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/event/dispatch/Direct.js:134)
wrappedFunction (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/Interface.js:451)
qx.Class.define.members.dispatchEvent (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/event/Manager.js:873)
qx.Class.define.statics.fireEvent (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/event/Registration.js:310)
qx.Mixin.define.members.fireEvent (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/core/MEvents.js:169)
qx.Class.define.members._onError (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/io/request/AbstractRequest.js:773)
(anonymous function) (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/lang/Function.js:293)
qx.Bootstrap.define.members._emit (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/bom/request/Xhr.js:440)
qx.Bootstrap.define.members.__readyStateChangeDone (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/bom/request/Xhr.js:897)
qx.Bootstrap.define.members.__readyStateChange (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/bom/request/Xhr.js:869)
qx.Bootstrap.define.members.__onNativeReadyStateChange (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/bom/request/Xhr.js:808)
(anonymous function) (/D:/qooxdoo-2.0.2-sdk/framework/source/class/qx/Bootstrap.js:551)
我发现有趣的是这个,在网络选项卡中。我希望这有帮助。