Created
November 2, 2016 15:19
-
-
Save t9toqwerty/6bd594dea300392860741a74db24f336 to your computer and use it in GitHub Desktop.
Basic Promise in Javascript
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
$(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