设为首页 加入收藏

TOP

手写Ajax的意义所在,从青铜到钻石!(二)
2019-09-17 17:04:31 】 浏览:40
Tags:手写 Ajax 意义 所在 青铜 钻石
",
    url: "http://localhost:8055/listcount.php",
    data: {search: "l"},
    dataType: "json",
    success: function (result) {
        alert(result["count"]);

 }
});

以上代码功能也是一样 但是感觉更好了 是不是有一点所谓jq中使用ajax的感觉了 此刻可以啦啦啦的 跳个舞了 千万不要满足

 

代码4:钻石水平

var $ = {
    ajax: function (json) {
        var req = new XMLHttpRequest();
        var type = json["type"];
        var url = json["url"];
        if (json["data"]) {
            var html = "?";
            for (var i in json["data"]) {
                html += i + "=" + json["data"][i] + "&";
            }
            html = html.substring(0, html.length - 1);
            url += html;
        }
        var success = json["success"];
        req.open(type, url, true);
        req.send();
        req.onreadystatechange = function () {
            if (req.readyState == 4 && req.status == 200) {
                var result = req.responseText;
                if (json["dataType"] == "json") {
                    result = JSON.parse(result);
                }
                success(result);
            }
        }
    }
}

$.ajax({
    type: "get",
    url: "http://localhost:8055/listcount.php",
    data: {search: "l"},
    dataType: "json",
    success: function (result) {
        alert(result["count"]);
   

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇pc端vue 滚动到底部翻页 下一篇从无建立一个vue项目

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目