Example #1
0
        public static object ExecutinonMethod(string ass, string className, string method, HttpContext context)
        {
            var result = new AjaxResult();
            try
            {
                var info = new MethodPathInfo
                               {
                                   Assembly = ass,
                                   ClassName = className,
                                   MethodName = method
                               };
                var helper = new MethodHelper(context, info);
                var m = helper.GetMethod();
                if (method != null)
                {
                    result.state = 1;
                    var rt = (helper.ExecutinonMethod(m) ?? string.Empty);
                    if (rt is string)
                        result.result = rt;
                    else
                        result.result = rt;

                }
                else
                {
                    result.state = 0;
                    result.msg = "方法调用失败!";
                }
                return result.state == 1 ? result.result : result;
            }
            catch (AjaxException ex)
            {
                return ex.GetResult();
            }
        }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            //暂时都是输出json格式
            context.Response.ContentType = "application/json";

            var result = new AjaxResult();
            try
            {
                var methodHelper = new MethodHelper(context, CurrentMethodPathInfo);
                var method = methodHelper.GetMethod();
                if (method != null)
                {
                    result.state = 1;
                    var rt = (methodHelper.ExecutinonMethod(method) ?? string.Empty);
                    if (rt is string)
                        result.result = rt;
                    else
                        result.result = rt.ToJson();

                }
                else
                {
                    result.state = 0;
                    result.msg = "方法调用失败!";
                }
                var callback = context.Request["callback"];
                var html = result.state == 1 ? result.result : result.ToJson();
                if(callback.IsNotNullOrEmpty())
                {
                    context.Response.ContentType = "application/x-javascript";
                    html = callback + "(" + html + ")";
                }
                context.Response.Write(html);
            }
            catch (AjaxException ex)
            {
                context.Response.Write(ex.Message);
            }
        }