qooxdoo远程请求未完成

时间:2012-09-16 15:47:31

标签: mysql json qooxdoo

我有简单的应用程序,我需要从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);
?>

我的问题是警报(“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)

我觉得有趣的是this,在网络标签中。我希望有所帮助。

1 个答案:

答案 0 :(得分:1)

首先,我建议使用qx.io.request.Xhr:

您将在此页面上详细了解如何使用它:

http://manual.qooxdoo.org/1.5/pages/communication/request_io.html

如果你使用Xhr,我会建议听“成功”和“失败”或“statusError”。 这会给你一些关于你的要求的错误。