未知的网络方法

时间:2015-07-26 14:34:45

标签: c# asp.net ajax

我正在尝试调用我用 [WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)] public void DisplayQuestionByIndex(int questionNumber) { DataRow e = questionTable.Rows[questionNumber]; QuestionTable t = new QuestionTable(); t.Id = Convert.ToInt32(e["Id"]); t.Question = e["Question"].ToString(); t.OptionA = e["OptionA"].ToString(); t.OptionB = e["OptionB"].ToString(); t.OptionC = e["OptionC"].ToString(); t.OptionD = e["OptionD"].ToString(); JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(t)); } 类修饰的代码隐藏方法,但我最终遇到了这个错误:

  

未知的网络方法[myMethodName]

这是我的方法:

$.ajax({
                url: "ExamPage.aspx/DisplayQuestionByIndex",
                data: '{questionNumber:'+ JSON.stringify(idToSend)+'}',
                contentType: "application/json;charset=UTF-8",
                dataType:"json",
                type: "POST",
                success: function (data,status) {
                    console.log(data.Id);
                    //console.log(data.Question);
                    //console.log(data.OptionA);
                    //console.log(data.OptionB);
                    //console.log(data.OptionC);
                    //console.log(data.OptionD);
                    //console.log(data);
                },
                error: function (request, status) {
                    console.log("An error has occured!");
                    console.log(status);
                },

            });

我的AJAX电话:

{{1}}

0 个答案:

没有答案