Good day. Here, I met a wonderful framework - qooxdoo.

I am writing ... writing and writing to the moment when I need to pass some parameters to AJAX. Here is the code for this class:

qx.Class.define("myhobby.api", { extend: qx.io.remote.Request, members : { call: function(fname, obj, callback){ this.setUrl("api.php"); this.setMethod("POST"); this.setData("act=" + fname); this.setAsynchronous(false); this.addListener("completed", function (e) { callback(e.getContent()); }); console.log(this.removeListener); this.send(); } } 

});

Further, for the sake of interest, I created a button and hung on it the event of executing the call function of this class. Code:

 var button1 = new qx.ui.form.Button("First Button", "myhobby/test.png"); var api = new myhobby.api(); button1.addListener("execute", function(e) { api.call(Math.random(10000, 9999), {name: 1}, function(e){ alert(e); }); }); 

The most indecent thing is that everything works fine only when you first click on the button. Now trace:

  1. We press on the button, api.call works (It always works)
  2. Next, we get into the call function, the listener fires, calls the callback function and passes it to it.

So here. On the second click of some x ... hell, the listener does not want to re-track the AJAX completion event. Do not understand why.

If there are comrades here who have worked with this framework ... I would be extremely happy :)) I hope for you :))

PS Digging on the Internet for a long time, did not find the answer.

    2 answers 2

    The issue is resolved through the castilla. But it works - a fact.

    1. I decided to inherit the object of my own class "myhobby".

    It turned out like this:

     qx.Class.define("myhobby.api", { extend: myhobby.Application, /*Вот тут я не стал наследовать "new qx.io.remote.Request" напрямую. Впринципе, мне это не нужно :)*/ members : { call: function(fname, obj, callback) { var ajax = new qx.io.remote.Request("api.php", "POST"); ajax.setData("act=" + fname); ajax.setAsynchronous(true); // this.setData(qx.util.Json.stringify(obj)); ajax.addListener("completed", function (e) { var answer = e.getContent(); callback(answer); }); ajax.send(); } } }); 

    Actually, here :) And what if someone helped :))

    The question can be considered closed :) Thank you all.

      The key was this ajax.setAsynchronous (true);

      • And no. What does the synchronicity do with it? I just did not include logic. one request = one instance. Therefore, it was impossible to make a request twice from one instance. after he finishes his destructive begins. - Stanislav Komar