Skip to content

Instantly share code, notes, and snippets.

@themodernpk
Last active November 1, 2016 20:23
Show Gist options
  • Save themodernpk/3089f3ff6aa87c7dad53cdb9509ab157 to your computer and use it in GitHub Desktop.
Save themodernpk/3089f3ff6aa87c7dad53cdb9509ab157 to your computer and use it in GitHub Desktop.
Ajax Call Back
(function (document, window, $) {
'use strict';
var TestModule = {
//--------------------------
funA: function () {
TestModule.handleAjax("http://google.com", {q: "test"}, "GET", "funB");
},
//--------------------------
funB: function (data) {
console.log(data);
},
//--------------------------
funC: function () {
TestModule.handleAjax("http://bing.com", {q: "test"}, "GET", "funD");
},
//--------------------------
funD: function (data) {
console.log(data);
},
//--------------------------
handleAjax: function (url, data, method, callbackfn) {
$.ajax({
method: "POST",
url: url,
data: data,
async: true,
context: this
}).done(function (response) {
TestModule.callbackfn(response) //<---------------- this should call after the ajax
});
}
//--------------------------
run: function () {
TestModule.funA();
}
};
//------------------------------------------------
window.TestModule = TestModule;
//------------------------------------------------
$(document).ready(function () {
TestModule.run();
});
//------------------------------------------------
})(document, window, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment