Javascript Ajax code for retrieving information

Source: Internet
Author: User

Client Code As follows: Copy code The Code is as follows: <HTML>
<Head>
<Script language = "JavaScript"> <! --
Function getit (){
If (document. getelementbyid ("url"). value = ""){
Alert ("Enter URL! ");
Return false;
}
If (document. getelementbyid ("count"). value = ""){
Alert ("Enter count! ");
Return false;
}
If (document. getelementbyid ("num"). value = ""){
Alert ("Enter num! ");
Return false;
}
If (document. getelementbyid ("end"). value = ""){
Alert ("Enter end! ");
Return false;
}
VaR url = Document. getelementbyid ("url"). value;
VaR COUNT = Document. getelementbyid ("count"). value;
VaR num = Document. getelementbyid ("num"). value;
VaR end = Document. getelementbyid ("end"). value;
Sendcall (URL, Count, num, end );
}
Function sendcall (URL, Count, num, end ){
If (parseint (Num) >=parseint (end) {return false ;}
VaR nurl = URL + "? Count = "+ Count +" & num = "+ num;
// Alert (nurl );
// Window. Open (nurl );
VaR XMLHTTP;
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
} Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
// Solve the cross-origin problem in FF
Try {
Netscape. Security. privilegemanager. enableprivilege ("universalbrowserread ");
} Catch (e ){
Alert ("permission universalbrowserread denied .");
}
}

XMLHTTP. onreadystatechange = function () {
If (XMLHTTP. readystate = 4 & XMLHTTP. status = 200) {
var STR = XMLHTTP. responsetext;
var MSG = document. getelementbyid ("getmsg");
If (Str. match (/thereisnothing/) {
MSG. innerhtml = "data has been transferred! "
}else {
// MSG. innerhtml = STR;
write (STR, Count, num);
var next = parseint (Num) + parseint (count);
sendcall (URL, count, next, end);
}< BR >}

XMLHTTP. Open ('post', nurl, true );
// XMLHTTP. setRequestHeader ("Content-Type", "text/XML ");
// XMLHTTP. setRequestHeader ("charset", "UTF-8 ");
XMLHTTP. Send (null );
}
Function write (STR, Count, num ){
VaR FSO = new activexobject ("scripting. FileSystemObject ");
VaR end = parseint (Num) + parseint (count );
VaR name = "E: \" + num + "-" + end + ". txt ";
VaR A = FSO. createtextfile (name, true );
A. writeline (STR );
A. Close ();
// Alert ("I have generated a" + name + "file under the root directory of your e disk! ");
Document. getelementbyid ("num"). value = end;
VaR MSG = Document. getelementbyid ("getmsg ");
MSG. innerhtml = "I have generated a" + name + "file under the root directory of your e disk! ";
}
// -->
</SCRIPT>
</Head>
<Body>

<Div>
Enter the setup then get the info:
</Div>

<Input id = "url" value = "http://www.oldjun.com/test.asp" size = "50">
<Input type = button value = "start" onclick = "javascript: getit ();"> <br>
<Div id = "getmsg">
</Div>

<Br>
→ How exactly once: <input name = "count" id = "count" type = "text" value = "1000" size = "30"/> <br>
→ Begin num: <input name = "num" id = "num" type = "text" value = "0" size = "30"/> <br>
→ End num: <input name = "end" id = "end" type = "text" value = "100" size = "30"/> <br>
</Body>

The function can be improved to prevent the interruption caused by failed access to information due to network congestion. It can be improved to implement many functional tools, such as ticket swiping... I only provide ideas for myself ~

Related Article

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.