Tôi có mã như thế này: tôi đang sử dụng giá trị Dữ liệu làm đối tượng theo nghĩa đen, thay vì ghép nối một Chuỗi. TẠI SAO? see hereThông báo: Nguyên thủy JSON không hợp lệ: phương thức jquery ajax với C# Webmethod
mã của tôi là thế này: -
$.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);
}
})
và WebMethod là như thế này:
[WebMethod]
public static string SaveClient(string projectSoid, string startDate, string endDate, string clientManager)
{}
Vấn đề là tôi đã nhận lỗi như thế này:
nhắn: không hợp lệ JSON nguyên thủy : projectSoid
Bạn cần phải JSON.strigify dữ liệu của bạn: 'dữ liệu: JSON.strigify ({ " projectSoid ": ProjectId, " startDate ": StartDate, " endDate ": EndDate, " clientManager ": Clien tManager }), ' – nemesv
Bất kỳ nhận xét nào về nhận xét của tôi? Bạn đã thử chưa? Nó có hoạt động không? – nemesv
tôi không biết JSON là gì. tôi nhận được lỗi rằng nó không hoạt động: ( –