日期:2014-05-18  浏览次数:20417 次

.net Jquery 调用后台带参数方法的问题
我前段的js代码如下
JScript code

$.ajax({
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            data: { "mid": d[0], "repost": d[1] },//d[0]=3395169326383796,d[1]=71
                            url: "Analytics.aspx/GetChartById",
                            dataType: "json",
                            success: function (cdata) {
                                var cjson = eval(cdata);
                                var chart = [];
                                $.each(cjson, function (j, c) {
                                    chart.push([c.Hour, c.Count]);
                                });
                                $("#chart_" + d[0] + "").jqChart({
                                    title: { text: 'JavaScript Array' },
                                    series: [
                                                {
                                                    type: 'line',
                                                    data: chart,
                                                    markers: { type: 'circle', size: 8 }
                                                }
                                            ]
                                });
                            },
                            error: function (errorString) {
                                $.each(errorString, function (e, err) {
                                    alert(err);
                                });
                            }
                        });



后台C#代码
C# code

        [WebMethod]
        public static string GetChartById(string mid,string repost)
        {
            return OAuth.SinaOuthBase.GetRepostDate(Int64.Parse(mid),int.Parse(repost));
        }


调用的时候总是报出 http500的错误 用vs的断点 运行的时候却无法进入断点debug
遍历js的错误代码找到如下说明:
Message":"无效的 JSON 基元: mid。","StackTrace":" 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n 在 System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n 在 System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n 在 System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n 在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException

我特意 用.net的button事件写了一个方法来验证参数 发现可以正常调用方法
C# code

        protected void btn_GetYesterdayData_Click(object sender, EventArgs e)
        {
            //Response.Write(OAuth.SinaOuthBase.GetRepostDate(3395169326383796,71));
        }




------解决方案--------------------
那你调用GetChartById(string mid,string repost)时,填入参数"33951693