【发布时间】:2014-06-12 06:01:53
【问题描述】:
下面的代码是我的服务器端代码。 (C#)
[WebMethod]
public static string InsertCV(string edu)
{
return "";
}
下面的代码是我的客户端代码。 (ASP.NET)
var edu = {"education":[{"university":"111","speciality":"222","faculty":"333","degree":"444","start":"555","end":"666"}]}
var post = $.ajax(
{
type: "POST",
data: edu,
url: "Add_CV.aspx/InsertCV",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false
})
post.done(function (data, teStatus, jqXHR) {
if (data.d == "")
{ alert("ok"); }
});
post.fail(function (jqXHR, e) {
alert("error");
});
我想用 ajax post 方法将用户的数据发送到服务器。但每次post.fail() 函数执行。
请帮助我,我的错误在哪里。
可能在服务器端 InsertCV(string edu) , string 不适合这种情况。我不知道。
【问题讨论】:
-
对不起,是我的错
-
可能是您以错误的方式传递数据。只需在 AJAX 调用的数据对象中尝试 JSON.stringify(edu) 即可。谢谢
-
@user3624946 使用浏览器开发者工具检查请求和服务器响应——即它是 403 吗? 404? 5xx?另外,尝试将调试器附加到 ASP.NET 代码,看看是否有任何异常。
-
@Arpit Jain,我试过了,但结果是一样的。
-
@user2864740 ,我尝试并得到错误 500。
标签: c# jquery ajax json webmethod