ASP.NET AJAX 到函数调用后面的代码错误
我正在使用以下调用将数据发送回服务器:
$.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!');
}
});
后面的代码看起来像
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;
}
}
}
来自 Chrome 的请求负载,即 UI 更新变量的值是: { IDS : "21TOK31" , VALUES : "2TOK2"}
请求没有命中函数后面的代码,并且 ajax 函数总是因为错误而进入失败块。
当没有传递数据并且代码隐藏函数没有参数时,请求会命中代码隐藏函数。
我是在 ASP.NET 中使用 JSON 的新手。有人可以指导我可能出现的问题吗?以及如何最好地解决这个问题。
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!');
}
});
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;
}
}
}
From Chrome the request pay load i.e. value of the UI updates variable is: { IDS : "21TOK31" , VALUES : "2TOK2"}
The request does not hit the code behind function and the ajax function always goes to the failure block because of the error.
The request hits the code behind function when no data is being passed and the code behind function has no parameters.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将错误函数修改为如下所示:
您将看到确切的错误。
就我个人而言,我只是在给我带来问题的函数中放置断点,然后在本地运行它来调试,
modify the error function to be like this:
and you will see the exact error.
personally i just put breakpoints inside the function giving me problems and run it locally to debug,
要进行问题排查:
如果如果您仍然遇到问题,请发布结果,这将为您提供正在发生的真正错误。
To troubleshoot:
If you're still having problems, post the result of that, which will give you the real error that's happening.
如果您使用以下内容,它是否有效:
webconfig 文件中还存在需要设置的配置设置,但我假设您由于空返回值而具有这些配置设置。
您可能需要的另一件事是转换器,因为 asp 返回数据的格式:(在您的 javascript ajax 调用中)
并更改:
If you use the following, does it work:
There are also configuration settings in the webconfig file that need set, but I make the assumption you have those due to your empty return value working.
One other thing you might need is a converter due to the format that asp returns data:(in your javascript ajax call)
and change: