-
21 Jun 2011 9:29 AM #1
How to get ajax request into a variable in sencha touch?
How to get ajax request into a variable in sencha touch?
What I am trying to do is is get the information I have in my ajax request as the badgetext number
Here is where I am trying to do it. This seems simple, but I cant figure it out.
PHP Code:Ext.Ajax.request({
url: '../lib/messages.php',
success: function(response, opts) {
var badge_number = Ext.decode(response.responseText);
console.dir(badge_number);
},
failure: function(response, opts) {
console.log('server-side failure with status code');
}
});
var buttonsGroup1 = [{
text: 'Messages',
//badge_number variable from ajax request would go here. badgeText: '2',
handler: tapHandler
}];
I just have the php script returning a number. The server responds fine and the success function works it retrieves the data. But I want the data that the success function gets from the php script to be the badgeText. My problem is that I do not know how to put that data into badgeText which is in the variable buttonsGroup1
-
21 Jun 2011 9:53 AM #2
You could do something like this in the ajax success function:
Code:success: function(response, opts) { var badge_number = Ext.decode(response.responseText); buttonsGroup1[0].badgeText = badge_number; },
-
21 Jun 2011 9:55 AM #3
is this way better
is this way better
Is this way better?
PHP Code:Ext.Ajax.request({
url: '../lib/messages.php',
success: function(response, opts) {
buttonsGroup1.setBadge(Ext.decode(response.responseText));
},
failure: function(response, opts) {
console.log('server-side failure with status code');
}
});
var buttonsGroup1 = new Ext.Button({
text: 'Messages',
handler: tapHandler
});
-
21 Jun 2011 10:02 AM #4
Try this out:
Create a global variable called badgeText with your projectname before it (shown below). Just switch 'PROJECTNAME' with your project folder's name.
That usually works for me.
Good luck!
Look for my changes (orange commented text) below:
If you aren't working on this in a project, try just creating a regular global variable to store the badgeText.PHP Code://PROJECTNAME.badgeText;
Ext.Ajax.request({
url: '../lib/messages.php',
success: function(response, opts) {
//PROJECTNAME.badgeText= Ext.decode(response.responseText);
//console.dir(PROJECTNAME.badgeText);
},
failure: function(response, opts) {
console.log('server-side failure with status code');
}
});
var buttonsGroup1 = [{
text: 'Messages',
//badgeText: PROJECTNAME.badgeText,
handler: tapHandler
}];
-
13 Mar 2013 3:48 AM #5
To get ajax request into a variable in sencha touch
To get ajax request into a variable in sencha touch
I got this example from Sencha tutorial
var myRequest = Ext.Ajax.request({ url: 'myUrl', failure: function(response) { console.log(response.aborted); // logs true } });
try this out.
http://jnelson.in


Reply With Quote