Results 1 to 2 of 2

Thread: Small understanding-Problem with AJAX / TaskMgr communication

  1. #1
    Sencha User
    Join Date
    Mar 2008
    Location
    Dsseldorf, Germany
    Posts
    9

    Default Small understanding-Problem with AJAX / TaskMgr communication

    Hi everybody,

    maybe it's just a little thing, but i don't get the idea. My Goal is to develop a very simple Ext.data.Store - which simply implements a getValue() Method.
    Code:
    My.AjaxReader = Ext.extend(Ext.util.Observable,{
      constructor: function () {..}
    
      getValue: function () {
        Ext.Ajax.request({
          url: 'foo.php',
          success: function() { this.value = respond.of.ajax; }),
          params: { foo: 'bar' }
        });
        return this.value;
      }
    });
    This store loads the data via ajax. There will be more stores, which load data from an array, or a xml-file (just like Ext.data.*). They all will have the method getValue() - so in an other Object i can use whatever store i want.

    Code:
    ElementCreator = Ext.extend(Ext.util.Observable,{
      init: function() {
        this.loader = new My.AjaxReader();
        Ext.TaskMgr.start( {
    			task: function() { this.value = this.loader.getValue(); }
    			delay : 3000 
    		});
      }
    });
    (This is just kind of pseudo-code)
    Now my problem is hard to describe, but how do i handle the callbacks? When ElementCreator (better: the TaskMgr) fetches the data via this.loader.getValue(), the ajax-request begins, but immediately the function returns.
    How do i get this.loader.getValue(); to return the value when the load succeeded but not before?

    Hope, you understand what i mean?

    Thank you very much for your help and patience

  2. #2
    Ext User
    Join Date
    Oct 2008
    Location
    Ger
    Posts
    178

    Default

    u have to wait for your serverresponse if i understand your problem right.....
    Code:
            Ext.Ajax.request({  
                url : 'yourURL.php'
                success: function(objServerResponse){
                     alert(objServerResponse.responseText);
                }
            });

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •