Skip to content

Instantly share code, notes, and snippets.

@t9toqwerty
Created November 2, 2016 15:19
Show Gist options
  • Save t9toqwerty/6bd594dea300392860741a74db24f336 to your computer and use it in GitHub Desktop.
Save t9toqwerty/6bd594dea300392860741a74db24f336 to your computer and use it in GitHub Desktop.
Basic Promise in Javascript
$(document).ready(function () {
fetchData(url, postdata).then(function (data) {
//handle data
});
});
function fetchData(links, apiCount) {
return new Promise(function (resolve, reject) {
$.ajax({
type: "POST",
url: 'url.php',
data: {
"data1": val1,
"data2": val2
},
success: function (data) {
resolve(data);
},
error: function (jqXHR, exception) {
reject(jqXHR.status);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment