Example of Ajax and PHP learning and training

Source: Internet
Author: User

This article introduces how to use Ajax and PHP by using an example to download the source code of this instance.ProgramFor better understanding. In the compressed package, functions. JS is the core of Ajax.CodeAll the operations are implemented through it. The Code explained below is extracted from functions. js.

Result 1: When you place the cursor over a notebook, if there is a memo on the day, it will be displayed, for example:

 Function Checkfortasks (thedate, e ){ // Find the corresponding <div> of taskbox on the page and set it to visible Theobject = Document . Getelementbyid (" Taskbox "); Theobject. style. Visibility =" Visible "; // Initialize the taskbox location    VaR Posx = 0; VaR Posy = 0; // Locate the taskbox position as the mouse position Posx = E. clientx + Document . Body. scrollleft; posy = E. clienty + Document . Body. scrolltop; theobject. style. Left = posx +" Px "; Theobject. style. Top = Posy +" Px "; // Set the PHP request page Serverpage =" Taskchecker. php? Thedate = "+ Thedate; // Set the location where PHP returns data replacement Objid =" Taskbox ";VaR OBJ = Document . Getelementbyid (objid ); // Send the request and load the returned data XMLHTTP. Open (" Get ", Serverpage); XMLHTTP. onreadystatechange = Function (){ If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200) {obj. innerhtml = XMLHTTP. responsetext ;}} XMLHTTP. Send ( Null );}

 

Result 2: When the mouse clicks a day to enter a name, the system will automatically retrieve whether the name exists, and you can enter the name box by selecting,

Function AutoComplete (thevalue, e ){ // Locate the <div> position of autocompletediv (displaying the tag of the retrieved name) on the page Theobject = Document . Getelementbyid (" Autocompletediv "); // Set to visible Theobject. style. Visibility =" Visible "; Theobject. style. width =" 152px "; // Set the tag location for search    VaR Posx = 0; VaR Posy = 0; posx = (findposx ( Document . Getelementbyid (" Yourname ") + 1); posy = (findposy ( Document . Getelementbyid (" Yourname ") + 23); theobject. style. Left = posx +" Px "; Theobject. style. Top = Posy +" Px "; // Set the event to keyboard input    VaR Theextrachar = E. Which; If (Theextrachar = undefined) {theextrachar = E. keycode ;} // Set the location for loading the search list    VaR Objid =" Autocompletediv "; // Set the PHP request page and pass the name entered by the user to the previous value (taking into account the role of backspace)    If (Theextrachar = 8 ){ If (Thevalue. Length = 1 ){ VaR Serverpage =" Autocomp. php ";} Else { VaR Serverpage =" Autocomp. php "+" ? Sstring = "+ Thevalue. substr (0, (thevalue.Length -1 ));}} Else { VaR Serverpage =" Autocomp. php "+" ? Sstring = "+ Thevalue + String . Fromcharcode (theextrachar );} // Send the request and load the returned data    VaR OBJ = Document . Getelementbyid (objid); XMLHTTP. Open (" Get ", Serverpage); XMLHTTP. onreadystatechange =Function (){ If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200) {obj. innerhtml = XMLHTTP. responsetext ;}} XMLHTTP. Send ( Null );}

Source codeDownload

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.