/// <summary> /// 注册一个网页数据获取,并指定返回字符串型式 /// </summary> /// <param name="ClientMethodName">客户端js调用名称</param> /// <param name="Url">要获取的网页数据地址</param> /// <param name="callBack">回调方法</param> public static void RegisterGet(string ClientMethodName, string Url, string callBack) { AjaxParame ap = new AjaxParame(Url); ap.callBack = callBack; RegisterGet(ClientMethodName, ap); }
/// <summary> /// 注册一个网页数据获取 /// </summary> /// <param name="ClientMethodName">客户端js调用名称</param> /// <param name="axpm">参数实例</param> public static void RegisterGet(string ClientMethodName, AjaxParame axpm) { if (axpm == null || string.IsNullOrEmpty(ClientMethodName)) { return; } if (string.IsNullOrEmpty(axpm.Url)) { return; } if (HttpContext.Current == null) { return; } Page page = (Page)HttpContext.Current.CurrentHandler; if (page.Header == null) { throw new AjaxHeadNotServer(); } StringBuilder Sb = new StringBuilder(); Sb.Append(" function "); Sb.Append(ClientMethodName); Sb.Append("("); for (int i = 0; i < axpm.Parames.Count; i++) { Sb.Append(axpm.Parames[i]); } Sb.AppendLine("){"); Sb.AppendLine(" var Aj = new eAjax(); "); if (!string.IsNullOrEmpty(axpm.callError)) { Sb.AppendFormat(" Aj.callError = {0};", axpm.callError); Sb.AppendLine(); } if (!string.IsNullOrEmpty(axpm.callBack)) { Sb.AppendFormat(" Aj.callBack = {0};", axpm.callBack); Sb.AppendLine(); } for (int i = 0; i < axpm.Parames.Count; i++) { Sb.AppendFormat(" Aj.Add('{0}',{0});", axpm.Parames[i]); Sb.AppendLine(); } Dictionary <string, string> .Enumerator en = axpm.SendData.GetEnumerator(); while (en.MoveNext()) { Sb.AppendFormat(" Aj.Add('{0}','{1}');", en.Current.Key, en.Current.Value); Sb.AppendLine(); } if (axpm.isPost) { Sb.AppendFormat(" return Aj.post('{0}');", axpm.Url); } else { Sb.AppendFormat(" return Aj.get('{0}');", axpm.Url); } Sb.AppendLine(); AjaxScriptControl Sc = new AjaxScriptControl(); Sc.Body = Sb.ToString(); page.Header.Controls.Add(Sc); }