In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you the content of sample analysis of ajax synchronous and asynchronous XMLHTTP. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In web scripting, asynchronous mode should be used in most cases; synchronous mode will hang up the current script engine, so when you use synchronous mode, you should know what you want. In C++ development, synchronous mode should be the mainstream, if you must use asynchronous mode plus callback, you can refer to Using IXMLHTTPRequest onreadystatechange from C++.
The following is the code to get the RSS file on the remote host in asynchronous mode. The key point is to set a callback function to IXMLHTTPRequest::onreadystatechange. To prevent the script from falling back to the console prematurely, the asyncDone variable is used to detect the current state. Of course, if you use XMLHTTP in a web page, you don't have to bother-- as long as the IE page is not closed, the callback function will not exit.
The copy code is as follows:
Var xmlhttp = new ActiveXObject ("MSXML2.XMLHTTP.6.0")
Var url = "https://www.jb51.net/rss.xml";
Var asyncDone = false
Try {
Xmlhttp.open ("GET", url, true)
Xmlhttp.onreadystatechange = onReadyStateChange
Xmlhttp.send (null)
/ / loop so that the program from quiting
While (! asyncDone) {
WScript.Sleep (100)
}
WScript.Echo (xmlhttp.responseText)
} catch (e) {
WScript.Echo (e)
}
Function onReadyStateChange () {
WScript.Echo ("readyState:" + xmlhttp.readyState)
If (xmlhttp.readyState = = 4) {
AsyncDone = true
}
}
The code for getting remote host resources in synchronous mode is much simpler:
The copy code is as follows:
Var xmlhttp = new ActiveXObject ("MSXML2.XMLHTTP.6.0")
Var url = "https://www.jb51.net/rss.xml";
Try {
Xmlhttp.open ("GET", url, false)
Xmlhttp.send (null)
WScript.Echo (xmlhttp.responseText)
} catch (e) {
WScript.Echo (e)
}
However, if you use synchronous mode in IE, because there is no callback mechanism and IE does not support script threading, the script will be suspended until the XMLHTTP returns. Notice that the IE interface itself hangs.
Thank you for reading! This is the end of this article on "sample Analysis of ajax synchronous and Asynchronous XMLHTTP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.