• 技术文章 >php教程 >PHP源码

    php+ajax 实例入门教程

    2016-06-08 17:29:09原创489

    php+js 实例入门教程网上很多,我们这款是边学边来看实例哦,告诉你快速入门ajax哦。

    function checkfortasks (thedate, e){
    //找到页面中taskbox对应

    设置为可见
    theObject = document.getElementById("taskbox");
    theObject.style.visibility = "visible";
    //初始化taskbox位置
    var posx = 0;
    var posy = 0;
    //定位taskbox位置为鼠标位置
    posx = e.clientX + document.body.scrollLeft;
    posy = e.clientY + document.body.scrollTop;
    theObject.style.left = posx + "px";
    theObject.style.top = posy + "px";
    //设置PHP请求页面
    serverPage = "taskchecker.php?thedate=" + thedate;
    //设置PHP返回数据替换位置
    objID = "taskbox";
    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);
    }

    function autocomplete (thevalue, e){
    //定位页面中autocompletediv(显示检索姓名的标签)的

    位置
    theObject = document.getElementById("autocompletediv");
    //设置为可见
    theObject.style.visibility = "visible";
    theObject.style.width = "152px";
    //设置检索标签位置
    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";
    //设定事件为键盘录入
    var theextrachar = e.which;
    if (theextrachar == undefined){
    theextrachar = e.keyCode;
    }
    //设定加载检索名单位置
    var objID = "autocompletediv";
    //设定PHP请求页面,并将用户输入的姓名传值过去(同时考虑到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);
    }
    //发送请求并加载返回数据
    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);
    }
    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:php 正则html网址代码 下一篇:php 格式化输出日期函数
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• extjs+php 增,删,修,查询的简单实例• php的memcache队列类• PHP 自动将 URL 地址封装成链接• php中GET和POST请求发送几种方法总结• PHP的面向对象一些理解
    1/1