-
22 Sep 2010 6:53 AM #1
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:
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.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");
All clues welcome.
Cheers,
n
-
22 Sep 2010 8:41 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
your problem is not scope but the fact that you don't know that Ajax requests are asynchronous.

Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
23 Sep 2010 3:21 AM #3
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
-
Assign a variable on ajax response
By extjs_new in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 8 Jun 2010, 8:32 AM -
[FIXED][3.??] Ext.Ajax response doesn't 100% emulate native response
By valcamo in forum Ext 3.x: BugsReplies: 3Last Post: 28 Jun 2009, 8:08 AM -
Ext.Ajax : Reading the response even when response is not complete.
By ikhwanhayat in forum Ext 2.x: Help & DiscussionReplies: 6Last Post: 12 May 2009, 4:58 PM -
Get response into a variable
By litumishra in forum Ext 2.x: Help & DiscussionReplies: 6Last Post: 22 Sep 2008, 1:41 AM -
need value from ajax call into variable
By dlbjr in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 13 Dec 2007, 12:41 PM


Reply With Quote