JS callback and the use of asynchronous loading

Source: Internet
Author: User

I used to be a rookie (though it's still very-_-| | The technology of asynchronous loading and callback function is very yearning, but also has not been used, this time because the page logic is too complex, a bunch of request logic, if still in order to request, the speed of the page ... The leader is scratching his head again.

People are forced out, so to study the next asynchronous and callback, the following is only my own opinion ah, for their own memories, do not like to spray:

The amount ... The amount ... Forget it, typing good trouble, directly on the code bar, it is not to read

Getalarmdata (Prov,function (arralarm) {
Console.log (Arralarm);
});

function Getalarmdata (areaid,callback) {
var arr = [];
$.ajax ({
Type: ' GET ',
URL: ' URL ',
DataType: ' Script ',
Cache:false,
Async:false,
Success:function () {
var n = alarminfo.count;
var arrdata = Alarminfo.data;
for (var i = 0;i<3;i++) {
var style = i==0 && 9 | | I==1 && 7 | | i==2 && 5;
var id = areaid.substr (0,style);
$.each (Arrdata,function (i,v) {
if (V[1].split ('-') [0] = = ID) {
Arr.push (v);
}
})
}
Callback (ARR);
}
})
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.