Packaging method
var axmq = {
//Queues
queues: [],
//network request
request: null,
//Execution queue
render: function() {
$(document).queue(axmq.queues);
},
//append queue
append: function(func) {
axmq.queues.push(func);
},
//clear queue
clear: function() {
$(document).dequeue();
if (0 === $(document).queue().length) {
axmq.queues = [];
$(document).clearQueue();
}
},
//POST request
post: function(args) {
var params = {
url: 'https://www.sample.com/api',
headers: {},
data: {},
buffer: function() {},
callback: function() {}
};
$.extend(params, args);
var headers = {
Accept: 'application/json;charset=utf-8'
};
if (Object.keys(params.headers).length > 0) {
$.extend(headers, params.headers);
}
if (axmq.request == null) {
axmq.request = $.ajax({
async: true,
type: 'POST',
url: params.url,
headers: headers,
data: params.data,
dataType: 'JSON',
beforeSend: function() {
params.buffer();
},
success: function(res) {
console.log(res);
axmq.request = null;
axmq.clear();
params.callback(res);
},
error: function(err) {
console.log(err);
axmq.request = null;
axmq.clear();
params.callback({
errcode: 5001,
errmsg: 'System busy'
});
}
});
}
},
//example
sample: function() {
axmq.append(function() {
axmq.post({
url: 'https://www.sample.com/api/a'
});
});
axmq.append(function() {
axmq.post({
url: 'https://www.sample.com/api/b'
});
});
axmq.append(function() {
axmq.post({
url: 'https://www.sample.com/api/c'
});
});
axmq.render();
}
};
Call example
axmq.sample();
Read More:
- Canvas: How to Implement Video Screenshot Function
- Electron: How to Use BrowserWindow to Create a Window
- torch.max Example (How to Use)
- How to Use Printf in HAL Library
- Docker: How to build a rabbitmq image cluster
- Websocket Front-end Call Example
- Windows Core Audio APIs: How to Progress Loopback Recording and Generate WAV File
- Opentelemetry + Jaeger Python Version Cross Service Call Example
- Python: How to Create List by Comprehension (Example Codes)
- Android: How to Add Background Music for Activity with Service
- C#: How to Get details of the directory where the currently running program is located
- MultipartFile Upload an Image Example
- Android: How to get the size of font you set (Example Code)
- File class details (get the file name, size, path, create, etc.)
- go sync.Mutex Lock Examples
- Echarts-for-React Example (Install, Import and Effect)
- Base64 Image Compression Example
- MAFIA: 1- OpenFlow statistics (Counters, Timestamps)(mafia-sdn/p4demos/demos/1-openflow/1.1-statistics/p4src/of.p4)
- Open CASCADE Technology 7.7.0 released
- Matplotlib Draw 3D scatter Diagram Example