zoukankan      html  css  js  c++  java
  • AjaxHelper 无刷新留言

    1 .无刷新留言
    <script type="text/javascript">
    function getIdObj(id) { return document.getElementById(id); }
    window.onload = function () {
    document.getElementById('btnSumbit').onclick = function () {
    var _Id = document.getElementById('txtId').value;
    var _Class = document.getElementById('txtClass').value;
    var str = 'id=' + _Id + '&className=' + _Class;

    var xhr = null;
    if (typeof XMLHttpRequest != 'undefined') {
    xhr = new XMLHttpRequest();
    } else {
    xhr = new ActiveXObject("Microsoft.XMLHttp");
    }
    xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
    var res = xhr.responseText;
    var msgObj=document.getElementById('msgId');
    if (res == 1)
    {
    msgObj.innerHTML = "提交成功!";
    msgObj.style.color = "green";
    var tboduObj = document.getElementById('tdid').getElementsByTagName('tbody')[0];
    var trObj = tboduObj.insertRow(-1);
    trObj.insertCell(-1).innerHTML = 1;
    trObj.insertCell(-1).innerHTML = _Class;
    trObj.insertCell(-1).innerHTML = _Id;

    }
    }
    };
    xhr.open('post', 'AddClass.ashx', true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.send(str);
    };
    };
    </script>
    2.JsHelper
    var JsHelper = {
    getXHR: function () {
    var xhr = null;
    if (typeof XMLHttpRequest != 'undefined') {
    xhr = new XMLHttpRequest();
    } else {
    xhr = new ActiveXObject('Microsoft.XMLHttp');
    }
    return xhr;
    },
    doAjax: function (method, url, data, isAyn, callback) {
    method=method.toLowerCase();
    var xhr = this.getXHR();
    xhr.open(method,url+(method=="get"?'?'+data:''), isAyn);
    if (method == 'get') {
    xhr.setRequestHeader('If-Modified-Since', 0);
    } else {
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    }
    xhr.onreadystatechange = function () {
    callback(xhr);
    };
    xhr.send(method != "get" ? data : null);
    }
    };
  • 相关阅读:
    【中山纪念中学六年级模拟赛】方格翻转 题解
    高斯消元
    net 控件开发资料
    使用自定义验证组件库扩展 Windows 窗体
    POJ 3032
    UVa 10878 Decode the tape
    C语言I博客作业03
    第十周助教总结
    第十二周助教总结
    C语言I博客作业06
  • 原文地址:https://www.cnblogs.com/qfkobe24/p/4272117.html
Copyright © 2011-2022 走看看