",
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"]);