Php + ajax example getting started-PHP source code

Source: Internet
Author: User
Tags getting started with php
Ec (2); there are a lot of tutorials on getting started with php + js instances online. Let's take a look at the example while learning and tell you how to get started with ajax. Functioncheckfortasks (thedate, e) {find the taskbox corresponding to & lt; div & gt; in the page and set it to visible theObjectdocument. getElementById (& quot; taskbox & quot;); theObject. st script ec (2); script

There are a lot of tutorials on getting started with php + js instances on the Internet. Let's take a look at the examples while learning. Let's tell you how to get started with ajax.

Function checkfortasks (thedate, e ){
// Find the corresponding taskbox in the page

Set 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 );
}

Function autocomplete (thevalue, e ){
// Locate

Location
TheObject = document. getElementById ("autocompletep ");
// 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 = "autocompletep ";
// 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 );
}

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.