mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 09:58:51 +00:00
Splited api function in two
This commit is contained in:
parent
2045e1294c
commit
c345e66bce
@ -3,7 +3,7 @@
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
ComunicWeb.common.api = {
|
||||
/**
|
||||
* Make an API request
|
||||
*
|
||||
@ -12,7 +12,7 @@
|
||||
* @param {Boolean} requireLoginTokens Specify if login tokens are required or not
|
||||
* @param {Function} nextAction What to do next
|
||||
*/
|
||||
ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, requireLoginTokens, nextAction){
|
||||
makeAPIrequest: function(apiURI, params, requireLoginTokens, nextAction){
|
||||
//Prepare the request URL
|
||||
var requestURL = ComunicWeb.__config.apiURL + apiURI;
|
||||
|
||||
@ -53,6 +53,24 @@ ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, requireLoginToke
|
||||
|
||||
//Prepare request response
|
||||
apiXHR.onreadystatechange = function(){
|
||||
ComunicWeb.common.api._on_state_change(apiXHR, nextAction);
|
||||
}
|
||||
|
||||
//Set request headers
|
||||
apiXHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
//Submit request
|
||||
apiXHR.send(datas);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle xhr request chnages
|
||||
*
|
||||
* @param {XMLHttpRequest} apiXHR The request element
|
||||
* @param {Function} nextAction What to do once the request is done
|
||||
*/
|
||||
_on_state_change: function(apiXHR, nextAction){
|
||||
|
||||
//We continue only if request is terminated
|
||||
if(apiXHR.readyState == 4){
|
||||
|
||||
@ -90,11 +108,5 @@ ComunicWeb.common.api.makeAPIrequest = function(apiURI, params, requireLoginToke
|
||||
if(nextAction)
|
||||
nextAction(result);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
//Set request headers
|
||||
apiXHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
//Submit request
|
||||
apiXHR.send(datas);
|
||||
};
|
@ -51,6 +51,8 @@ var ComunicWeb = {
|
||||
* Make an API request
|
||||
*/
|
||||
makeAPIrequest: function(apiURI, params, requireLoginTokens, nextAction){},
|
||||
|
||||
//TODO : implement
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user