Last active
November 1, 2016 20:23
-
-
Save themodernpk/3089f3ff6aa87c7dad53cdb9509ab157 to your computer and use it in GitHub Desktop.
Ajax Call Back
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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