XMLHTTP trial notes

xiaoxiao2021-03-06  16

1 What is XMLHTTP XMLHTTP is a browser object that can be used to simulate the GET and POST requests for HTTP. With JavaScript, you can realize the page data update in the free refreshed, if the application can be achieved on the chat room, the text live broadcast can achieve better visual effects. 2 The XMLHTTP object in IE In the IE XMLHTTP is implemented as an ActiveX object, usually using VAR XMLHTTP = New ActiveXObject ("MSXML2.XMLHTTTTTTTTP"); to create an object, then use the OPEN method of the object to issue an HTTP request. XMLHTTP.Open ("get", fragment_url); this will have an HTTP request, and we need to register an anonymous function to the onReadyStateChange method for the XMLHTTP object, so when the request returns, XMLHTTP will automatically call this function we registered. The next is an actual example. XMLHTTP.ONREADYSTATECHANGE = function () {if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {element.innerhtml = xmlhttp.responseText;}} Because we don't need to send any information, the next statement ends xmlhttp.send (null); we will process the upper side of a package function, the lower is the complete code for this function: function loadFragmentInToElement (fragment_url, element_id) {var element = document.getElementById (element_id); var xmlhttp = new ActiveXObject ( " Msxml2.XMLHTTP "); xmlhttp.open (" GET ", fragment_url); xmlhttp.onreadystatechange = function () {if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {element.innerHTML = xmlhttp.responseText; }} xmlhttp.send (null);} The call method of the function is as follows: LoadFragmentIntoElement ('http://domain.com/ur.php', DynamicContent_ID); With the code on the upper side, with the JavaScript timing function, We can realize the latest non-refresh data updated, and the following functions are updated every 5 seconds.

转载请注明原文地址:https://www.9cbs.com/read-42397.html

New Post(0)