Nes*_*r C 19 c# asp.net jquery asp.net-ajax
我使用数据值作为对象文字,而不是连接一个字符串,如本答案中所述
我的代码如下:
$.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);
}
})
Run Code Online (Sandbox Code Playgroud)
我的网络方法是这样的:
[WebMethod]
public static string SaveClient(string projectSoid, string startDate,
string endDate, string clientManager)
{
...
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
消息:无效的JSON原语:projectSoid
nem*_*esv 39
有了你,contentType: 'application/json; charset=utf-8'
你声称你将发送JSON,但目前你的data
财产没有持有JSON.
您需要data
使用以下JSON.stringify
方法将您转换为JSON :
所以将您的data
财产改为:
data: JSON.stringify({
"projectSoid": ProjectId,
"startDate": StartDate,
"endDate": EndDate,
"clientManager": ClientManager
}),
Run Code Online (Sandbox Code Playgroud)
您应该注意,JSON.stringify
旧版浏览器本身不支持该方法,因此您可能需要提供使用以下各种库之一的实现:
Douglas Crockford的JSON2库.
归档时间: |
|
查看次数: |
33884 次 |
最近记录: |