zoukankan      html  css  js  c++  java
  • ajax封装

    function ajax(type, url, success, error) {
        var ajax = new XMLHttpRequest();
        if (type.toLowerCase() == 'post') {
            if (url.indexOf('?') == -1) {
                ajax.open(type, url, true);
                ajax.setRequestHeader('Content-type', 'application/x-www-formurlencoded');
                ajax.send();
            } else {
                url = url.split('?');
                ajax.open(type, url[0], true);
                ajax.setRequestHeader('Content-type', 'application/x-www-formurlencoded');
                ajax.send(url[1]);
            }
        } else {
            ajax.open(type, url, true);
            ajax.send();
        }
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4) {
                if (ajax.status == 200) {
                    // 请求成功以后
                    success && success(ajax.responseText);
                } else {
                    // 错误信息
                    error && error(ajax.status);
                }
            }
        }
    
    }
  • 相关阅读:
    Java内置包装类
    for循环思路题
    常用函数
    函数
    冒泡排序
    数组的运用
    for循环中有意思的练习题。
    for循环
    运算中容易出现的错误
    分支的运用
  • 原文地址:https://www.cnblogs.com/huchangwu/p/12048892.html
Copyright © 2011-2022 走看看