Features
- ce12fb3 Feat: ajax (#44)
- A module for the Ajax request. [API Page]
- If the browser supports
Promise
, return thePromise
object. If not, returnnull
after complete the Ajax call. - It supports
beforeRequest
,success
,error
, andcomplete
callbacks. - Common configurations can be specified in
ajax.defaults
. - It provides ES6(
tui-code-snippet/ajax/index.mjs
) and transpiled(tui-code-snippet/ajax/index.js
) files. Transpiled version supports IE8+.
- If the browser supports
- A module for the Ajax request. [API Page]
import ajax from 'tui-code-snippet/ajax'; // import ES6 module (written in ES6)
// import ajax from 'tui-code-snippet/ajax/index.js'; // import transfiled file (IE8+)
ajax({
url: 'https://nhn.github.io/tui-code-snippet/2.3.0/latest',
method: 'POST',
contentType: 'application/json',
params: {
version: 'v2.3.0',
author: 'NHN. FE Development Lab <dl_javascript@nhn.com>'
},
beforeRequest: () => {
showProgressBar();
},
complete: () => {
hideProgressBar();
}
}).then(({ data }) => {
console.log(data);
}).catch(({ status, statusText }) => {
console.error(`${status} - ${statusText}`);
});