'how to get value from Ext.Ajax.request
Ext.Ajax.request({
url:'abc/abc/abc',
success: function(response){
var result = Ext.decode(response.responseText);
var value=result.roles;
}
});
How can I get "value=result.roles" from ext.ajax.request?
I am trying to use an action.
Ext.Ajax.request({
url:'abc/abc/abc',
success: function(response){
var result = Ext.decode(response.responseText);
var value=result.roles;
getValue(value);
}
});
function getValue(value) {
return value;
};
But I still can't get the value.
How can I do this?
Solution 1:[1]
You need to use this:
success: function ( result, request ) {
var jsonData = Ext.util.JSON.decode(result.responseText);
var resultMessage = jsonData.data.result;
fn_AKExt(resultMessage, ‘Success’);
},
failure: function ( result, request ) {
var jsonData = Ext.util.JSON.decode(result.responseText);
var resultMessage = jsonData.data.result;
fn_AKExt(resultMessage, ‘Error’);
}
Check out How To Use Ext.Ajax.Request With Response Text for more details.
Solution 2:[2]
$.ajax({
async: false,
type: "GET",
url :"url",
data :"",
success:(data){
functionOutSideAjax(parameter);
}
});
functionOutSideAjax(var){
useThisVar = parameter;
}
Create your function() outside the ajax response then pass the required values from your ajax response and then you can use "useThisVar" where ever you want in javascript file ..
Solution 3:[3]
Normally, the AJAX request is asynchronous. That's why we do not get the value out of the request. If we set async:false, then we can get the value.
var cnt;
Ext.Ajax.request({
method: 'POST',
async:false,
url: '...',
params: {},
success: function (response) {
var cnt= Ext.decode(response.responseText);
}
});
return cnt;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | RanchoX |
Solution 3 | kc2001 |