diff --git a/src/framework/ajax.js b/src/framework/ajax.js index 3b9ccb9..89f04ad 100644 --- a/src/framework/ajax.js +++ b/src/framework/ajax.js @@ -73,7 +73,7 @@ }); this.#callbacks.forEach((data)=>{ if(data.callback_complete !== undefined){ - data.callback_complete(this.#xhr, this.#xhr.statusText,error); + data.callback_complete({}, this.#xhr, this.#xhr.statusText,error); } }); }; @@ -84,6 +84,37 @@ } }); }); + this.#xhr.addEventListener("load", (evt) => { + var response = {}; + if(this.#xhr.readyState == 4){ + try{ + response=JSON.parse(this.responseText) + }catch(error){ + response = this.responseText; + } + this.#callbacks.forEach((data)=>{ + if(data.callback_success !== undefined){ + data.callback_success(response, this.#xhr, this.#xhr.statusText, this.#xhr.status); + } + }); + this.#callbacks.forEach((data)=>{ + if(data.callback_complete !== undefined){ + data.callback_complete(response, this.#xhr, this.#xhr.statusText, this.#xhr.status); + } + }); + }else{ + this.#callbacks.forEach((data)=>{ + if(data.callback_error !== undefined){ + data.callback_error(this.#xhr, this.#xhr.statusText, this.status); + } + }); + this.#callbacks.forEach((data)=>{ + if(data.callback_complete !== undefined){ + data.callback_complete({}, this.#xhr, this.#xhr.statusText, this.status); + } + }); + } + }); } }; f.ajax=function(args) {