【发布时间】:2013-02-23 23:32:45
【问题描述】:
我使用数据值作为对象字面量,而不是像this answer 中解释的那样连接字符串
我的代码如下:
$.ajax({
url: "../Member/Home.aspx/SaveClient",
type: "POST",
async: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: {
"projectSoid": ProjectId,
"startDate": StartDate,
"endDate": EndDate,
"clientManager": ClientManager
},
success: function(response) {
if (response.d != "") {
}
},
error: function(response) {
var r = jQuery.parseJSON(response.responseText);
alert("Message: " + r.Message);
alert("StackTrace: " + r.StackTrace);
alert("ExceptionType: " + r.ExceptionType);
}
})
我的网络方法是这样的:
[WebMethod]
public static string SaveClient(string projectSoid, string startDate,
string endDate, string clientManager)
{
...
}
但我收到以下错误:
消息:无效的 JSON 原语:projectSoid
【问题讨论】:
-
你需要 JSON.strigify 你的数据:
data: JSON.strigify({ "projectSoid": ProjectId, "startDate": StartDate, "endDate": EndDate, "clientManager": ClientManager }), -
对我的评论有意见吗?你试过了吗?有用吗?
-
我不知道 JSON.strigify 是什么?我收到错误提示它不起作用:(
-
您使用的是哪个浏览器?在旧版浏览器中您可能需要json2
-
Nestor 出现错误,因为 nemesv 拼写错误(错过了 n):JSON.stringify
标签: c# jquery asp.net asp.net-ajax