问题描述
我使用下面的调用将数据发送回服务器:
I am using the following call to send data back to the server:
$.ajax({
type: "POST",
url: "MyTestPage.aspx/UpdateData",
data: updates,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert('Success!');
},
error: function (msg) {
alert('Failure!');
}
});
在code背后看起来像
The code behind looks like
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace TestNamespace
{
public partial class MyTestPage: System.Web.UI.Page
{
[WebMethod]
public static bool UpdateData(string IDs, string Values)
{
return true;
}
}
}
从浏览器请求有效载荷,即用户界面的值更新变量为: {IDS:21TOK31值:2TOK2}
不打身后功能code和总是AJAX功能的请求到达,因为错误的故障块。
The request does not hit the code behind function and the ajax function always goes to the failure block because of the error.
请求命中背后功能code当没有数据传递和背后功能code没有参数。
The request hits the code behind function when no data is being passed and the code behind function has no parameters.
我是新来ASP.NET中使用JSON。可有人请指引我是什么问题呢?以及如何可能得到解决。
I am new to using JSON in ASP.NET. Can someone please guide me to what the problem might be? And how best it might be solved.
推荐答案
修改误差函数是这样的:
modify the error function to be like this:
error: function (xhr, err) { alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status + "\nresponseText: " + xhr.responseText); }
和您将看到确切的错误。
and you will see the exact error.
我个人只是把断点在函数内部给我的问题,并在本地运行调试,
personally i just put breakpoints inside the function giving me problems and run it locally to debug,
这篇关于后面的函数调用错误ASP.NET AJAX至code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!