Ajax method source code I have seen, is the Ajax method calls a callback, first execute the Ajax method and then execute the callback, which is different from the normal reference function? So the async callback of Ajax is in the experience where;
Reply content:
Ajax method source code I have seen, is the Ajax method calls a callback, first execute the Ajax method and then execute the callback, which is different from the normal reference function? So the async callback of Ajax is in the experience where;
The top few really irrelevantly replying. First, the browser's JS engine is single-threaded, and performing a time-consuming operation must hinder the execution of the thread's subsequent code (such as waiting for a response from the network request). Some languages solve this problem by opening a sub-thread and putting the time-consuming action on the child thread. The JS engine itself does not support multi-threading, but the browser basically has three threads: JS engine thread, Event trigger thread, HTTP request thread. After the two threads are triggered, the corresponding callback function is placed in the execution queue of the JS engine thread for queuing, as long as the JS engine thread is idle and then executes the callback function added to the queue in turn. Of course, the execution of these callback functions is still blocking the thread.
The page does not refresh the data request, returns the data through the JS Operation Dom, the user experience is good; simply call the JS function only to the front-end operation, no interaction with the server; Ajax is a combination of technology to enhance the user experience, do not have to refresh the entire page every request, that is, JS Operation Dom for local refresh
In my opinion, there is no difference in nature, an incoming function, a similar object-oriented I polymorphic overrides (perform default or custom overrides)
References such as: //Get User Data Function getDate () { }
//Login Function Login (CB) {
//Login logic ...//Login successful after execution callback reference if (CB && typeof cb = = = ' function ') {CB (); }
}
Login (getDate);
Ajax can be implemented internally (not sure it is, just simulate it)
function XMLHttpRequest () { }
You can have a default or no, not when the send callback is executed. XMLHttpRequest.prototype.onreadystatechange = function () {};
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.