问题描述
- $.getJSO求大神帮忙写下ASP页面代码 小弟不胜感激
- 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_typeoutcolor"": outcolorincolor"": incolorimgurl"": imgurltitle"": 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"":3g_Port"":9999g_Toname"":""*test44""g_Experience"":1.0IsMG"":trueIsGuard"":false}{""m_Name"":""*兮兮""n_Name"":""守""n_Gride"":4g_Port"":0g_Toname"":""""g_Experience"":0.0IsMG"":trueIsGuard"":false}])
解决方案
jsonp其实就是一段可以执行的js代码,获取回调函数名称输出符合js语法的语句即可
cb=request.querystring(""jsoncallback"")'获取回调函数名称data=""""'读数据组合成回调需要的json数据格式,赋值给data变量response.write cb&""(""&data&"")""'输出js代码
时间: 2024-11-16 07:08:28