
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
extend-ajax
Advanced tools
npm i extend-ajax --save
send a simple post request
ajax('test/post', 'post').send({
text: 'hello'
}).then(({data})=> {
console.log(data);
})
send a post request and specify global options
var ajax = require('extend-ajax');
ajax.config({
host: 'http://xxx.com/',
convert: (data) => {
return JSON.parse(data);
},
cacheSize: 2
});
ajax('test/post', 'post', {
header: {
'Content-Type': 'json',
'Accept': 'json'
}
}).send().then(({data})=> {
console.log(data);
})
file upload(IE10+)
html:
<input name = "file" type = "file" id = "file">
js:
var ajax = require('extend-ajax');
var files = document.getElementById('file').files;
var fileUpload = ajax('/upload', 'post', {
header: {
'Content-Type': 'formData'
}
}).send({
file: files
}).then(() => {
alert('file is successfully uploaded');
});
jsonp
var JSONP = ajax('/test/jsonp', 'jsonp', {
jsonpParam: 'callback',
jsonpName: 'getDataByJsonp'
});
JSONP.on('success', function (data) {
console.log('get data:' + data + ' with jsonp');
done();
});
JSONP.send();
create one ajax object, but it can't send a request immediately, you need use ajax.send() to send a request.
url <string> a reequest url
method <string> request method。default: 'post'.
options <object>
send the ajax request, if browser support Promise, it will return Promise.If not or jsonp, it will return itself.
abort the ajax request
when browser can't support Promise,ajax.send() will return the ajax object, so you can use ajax.then() to get response.But if type is 'jsonp',ajax.then() will don't work.
add event listener for the ajax object.if async is false, ajax.on() must be called before send,else it will not work.
specify global options, each ajax object will apply the options and own options.
Please use version 1. X and 0. X.
FAQs
an AJAX request library
The npm package extend-ajax receives a total of 36 weekly downloads. As such, extend-ajax popularity was classified as not popular.
We found that extend-ajax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.