Php+ajax Example Getting Started Tutorial

Source: Internet
Author: User
Tags visibility

Php+js Instance Tutorial Online A lot of, we this is to learn while looking at the example Oh, tell you quick start Ajax Oh.

function Checkfortasks (Thedate, E) {
Find Taskbox <div> set to visible in page
Theobject = document.getElementById ("Taskbox");
theObject.style.visibility = "visible";
Initialize Taskbox position
var posx = 0;
var posy = 0;
Locate Taskbox position as 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 up the PHP request page
Serverpage = "taskchecker.php?thedate=" + thedate;
Set PHP return Data replacement location
ObjID = "Taskbox";
var obj = document.getElementById (ObjID);
Send request and load return 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 the <div> position of the Autocompletediv in the page (showing the label that retrieves the name)
Theobject = document.getElementById ("Autocompletediv");
Set to visible
theObject.style.visibility = "visible";
TheObject.style.width = "152px";
Set Retrieve label location
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";
Setting Events for keyboard entry
var Theextrachar = E.which;
if (Theextrachar = = undefined) {
Theextrachar = E.keycode;
}
Set Load Search list location
var ObjID = "Autocompletediv";
Set the PHP request page and pass the user's name to the past (taking into account the backspace effect)
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 request and load return 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.