Here I'm calling an AJAX request with this "Security.createAuthenticatedAjaxRequest(session, URL)" method and I want to return the response of that request. But, it seems like the response doesn't wait until the request completes. It returns undefined as the response. I think it's because it returns the response before ajax request completes.
function minAndMaxGradeAllowedRequest(session) { if (Common.isEmpty(minAndMaxGradeAllowed)) {
Security.createAuthenticatedAjaxRequest(session, URL).then(function(minAndMaxGradeAllowedResponse) {
minAndMaxGradeAllowed = minAndMaxGradeAllowedResponse;
}).fail(function(error) {
LOGGER('Failed to find Shaywitz Min and Max grades information', error.toString());
}); } return minAndMaxGradeAllowed; }
createAuthenticatedAjaxRequest: function(session, url, config){
if(Common.isEmpty(config)) {
config = {};
}
return this.createAuthenticatedAjaxRequestWithAcceptHeaderParam(session, url, config, true);
},
createAuthenticatedAjaxRequestWithAcceptHeaderParam: function(session, url, config, isAcceptRequired){
if(Common.isEmpty(config)) {
config = {};
}
if(Common.isEmpty(config.headers)) {
config.headers = {};
}
config.headers['Authorization'] = 'Bearer ' + session.get('data.authenticated.access_token');
if(!Common.isEmpty(isAcceptRequired) && isAcceptRequired === true) {
config.headers['Accept'] = 'application/json';
}
if(Common.isNotEmpty(session.get('data.authenticated.supportuser'))){
config.headers['supportuser'] = session.get('data.authenticated.supportuser');
}
return Ember.$.ajax(url, config);
},
Below is the code where it uses the response of the function minAndMaxGradeAllowedRequest(session).
let minAndMaxGradeAllowed = ShaywitzGradesAllowed.getMinAndMaxGradeAllowed(this.get('session'));
I don't have much experience with Ember js. Can someone please help me to solve this problem?
Aucun commentaire:
Enregistrer un commentaire