0

I have simple application and i need to get data from MySQL. I read that i can do it using script on server in *.php file and all i need to do is just run this file from my qooxdoo application and get printed data. Here is piece of code:

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 file:

<?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);
?>

My problem is that alert("Something"); is never showed just like completed event is never fired. I have tried also different events, but none helped. I'm sure that db_connect.php is opened, because i have checked that.


Okay, i edited my code to use Xhr request and now it looks like:

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);

But the problem is that i always get fail event fired and in alert i have message:

fail null. Code 0

I added breakpoint right before alert and that's stack trace (using Chrome and 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)

Also what i found interesting is this, in Network tab. I hope that helped.

Blood
  • 4,126
  • 3
  • 27
  • 37

1 Answers1

1

First I would propose to use qx.io.request.Xhr :

You get a detailed introduction about to use it at this page:

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

If you use Xhr, i would propose to listen to "success" and "fail" or "statusError". This give you a hint of whats wrong with your request.

czuendorf
  • 853
  • 6
  • 9
  • Thanks. Now something has changed but still have problems ;/ – Blood Sep 17 '12 at 08:53
  • Could you please post the stack trace you got? – czuendorf Sep 17 '12 at 09:42
  • Try to run your app from localhost and fire your request again. Xhr requests are only allowed from localhost in this case. – czuendorf Sep 17 '12 at 13:41
  • or you could also copy the build version into your server's htdocs and run this on localhost. – czuendorf Sep 17 '12 at 13:42
  • Okey i transfered files to localhost and all works. Weird stuff :D Last question and i'll accept your answer - how i can build 'release' version that i don't have to copy all qooxdoo files to my server? – Blood Sep 17 '12 at 15:01
  • ./generate.py build should do the trick. You can also change the output directory of your build via your local config.json For better understanding of the problem you had, please read the following article: http://developer.chrome.com/extensions/xhr.html – czuendorf Sep 17 '12 at 15:31