📄 request-text.js
字号:
/*
This example must be run from a web server... for example by uploading to your ISP and viewed over the web, or placing the source files in the web pages directory of a web server on your own system and viewed by entering http://localhost/http-request.html in your browser address field - assuming your server alias is "localhost" as usual.
*/
var http_request = false;
// global variable for HTTPRequest
// function to request text from a specified url...
function make_request() // execute an HTTPRequest
{
if (window.XMLHttpRequest) // create an HTTPRequest object...
{ // for IE7, Mozilla, Safari ...
http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject) // or create an HTTPRequest object...
{ // for Internet Explorer 6...
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
else return false; // or quit...
http_request.open("GET","data.txt",true); // make the request to the server...
http_request.send(null); // stating method, filename, async
http_request.onreadystatechange=show_text;
}
function show_text()
{
if(http_request.readyState == 4) // if complete
{
if(http_request.status == 200) // if OK
{
window.document.getElementById("cell").innerHTML = http_request.responseText; // assign the returned text
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -