var ghost = window.location.hostname+":2258";
function Guard() {
this.Users = new Array();
this.GetCount = function () { return this.Users.length; }
this.FindObject = function (name) { var u = null; $.each(this.Users, function (i, v) { if (v.m_Name == name) { u = v; return false; } }); return u; }
this.GuardUserObject = function (m_Name, n_Name, n_Gride, g_Port, g_Toname, g_Experience, IsMG, IsGuard) { this.m_Name = m_Name; this.n_Name = n_Name; this.n_Gride = n_Gride; this.g_Port = g_Port; this.g_Toname = g_Toname; this.g_Experience = g_Experience; this.IsMG = IsMG; this.IsGuard = IsGuard; }
this.SortDesc = function () { this.Users = this.Users.sort(function (a, b) { return b.g_Experience - a.g_Experience; }); }
this.SortAsc = function () { this.Users = this.Users.sort(function (a, b) { return a.g_Experience - b.g_Experience; }); }
this.RemoveAll = function () { for (var i = 0; i < this.GetCount(); i++) { delete this.Users[i]; } this.Users.length = 0; }
this.RefreshUsers = function (json) { this.RemoveAll(); for (var i = 0; i < json.length; i++) { if (json[i].m_Name.indexOf("*") == 0 && (json[i].IsMG || (json[i].IsGuard && json[i].g_Port == parent.roominfo.Port))) { var um = new this.GuardUserObject(json[i].m_Name, json[i].n_Name, json[i].n_Gride, json[i].g_Port, json[i].g_Toname, json[i].g_Experience, json[i].IsMG, json[i].IsGuard); this.Users[this.GetCount()] = um; this.SortDesc(); } } }
this.GetUserTypeInfo = function (name) { var outcolor = ""; var incolor = ""; var imgurl = ""; var title = ""; var user_type = 0; var u = this.FindObject(name); if (u != null) { if (u.IsMG) { user_type = u.n_Gride + 3; imgurl = "http://" + ghost + "/images/yy/noble/icon_noble" + u.n_Gride + ".png"; title = u.n_Name; } else if (u.IsGuard) { user_type = parseInt(u.g_Experience); imgurl = "http://" + ghost + "/images/yy/guardian/guardian_0" + parseInt(u.g_Experience) + ".png"; title = "守护"; } return { "user_type": user_type, "outcolor": outcolor, "incolor": incolor, "imgurl": imgurl, "title": title }; } else { return null; } }
}
var Guard_Json = null;
$(document).ready(function () { $.getJSON("http://www.abc.com/0.asp?jsoncallback=?", { type: "ALL", port: parent.roominfo.Port }, function (data) { Guard_Json = new Guard(); Guard_Json.RefreshUsers(data); }); });
这个是结果ASP页面具体该如何写呢
jQuery1709215810747113315_1419650668218([{"m_Name":"*test22","n_Name":"神","n_Gride":3,"g_Port":9999,"g_Toname":"*test44","g_Experience":1.0,"IsMG":true,"IsGuard":false},{"m_Name":"*兮兮","n_Name":"守","n_Gride":4,"g_Port":0,"g_Toname":"","g_Experience":0.0,"IsMG":true,"IsGuard":false}])
jsonp其实就是一段可以执行的js代码,获取回调函数名称输出符合js语法的语句即可
cb=request.querystring("jsoncallback")'获取回调函数名称
data=""
'读数据组合成回调需要的json数据格式,赋值给data变量
response.write cb&"("&data&")"'输出js代码
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。