1. #1
    Ext User
    Join Date
    Apr 2009
    Posts
    31
    Vote Rating
    0
    n3b is on a distinguished road

      0  

    Default ajax response to variable

    ajax response to variable


    I'm trying to assign the response of an Ext.ajax.request to a variable but I'm failing at every turn. Basically I want to do something like:

    Code:
    function getAjaxJson( url, method ){
    
    		var json;
    		Ext.Ajax.request({
    			url : url, 
    			method: (method==null) ? 'GET' : method,
    			timeout: 180000,
    			success: function ( response ) {
    				json =  Ext.decode(response.responseText);
    			},
    			failure: function ( response ) { 
    				Ext.MessageBox.alert('Failed', response.responseText);
    			},
    			scope: this
    		});
    
    		return json;
    }
    
    var mydata = getAjaxJson("someurl");
    I know the scope must be wrong (I see the json variable getting populated then becoming undefined after the callback terminates) - I need some pointers.

    All clues welcome.

    Cheers,
    n

  2. #2
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Vote Rating
    79
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    your problem is not scope but the fact that you don't know that Ajax requests are asynchronous.

  3. #3
    Ext User
    Join Date
    Apr 2009
    Posts
    31
    Vote Rating
    0
    n3b is on a distinguished road

      0  

    Default yeah that was a silly mistake

    yeah that was a silly mistake


    Yeah it was a facepalms moment.

    Thanks for the response.

    n

Similar Threads

  1. Assign a variable on ajax response
    By extjs_new in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 8 Jun 2010, 8:32 AM
  2. Replies: 3
    Last Post: 28 Jun 2009, 8:08 AM
  3. Ext.Ajax : Reading the response even when response is not complete.
    By ikhwanhayat in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 12 May 2009, 4:58 PM
  4. Get response into a variable
    By litumishra in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 22 Sep 2008, 1:41 AM
  5. need value from ajax call into variable
    By dlbjr in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 13 Dec 2007, 12:41 PM

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi