я есть Ajax запрос на URL-адрес DataProcessor.aspx, как показано ниже, как я могу написать asp.net C# код для извлечения JSON данных из запроса и отображения в DataProcessor.aspx страницеAjax метод JQuery сообщение
var json = "{'ItemName':'" + escape(item.val()) + "','CategoryID':'" + category.val() + "','RecordID':'" + record.val() + "'}";
alert(escape(item.val()));
alert(category.val());
alert(record.val());
var ajaxPage = "DataProcessor.aspx?Save=1"; //this page is where data is to be retrieved and processed
var options = {
type: "POST",
url: ajaxPage,
data: json,
contentType: "application/json;charset=utf-8",
dataType: "json",
async: false,
success: function(response) {
//alert("success: " + response);
},
error: function(msg) { alert("failed: " + msg); }
};
//execute the ajax call and get a response
var returnText = $.ajax(options).responseText;
if (returnText == 1) {
record.html(returnText);
$("#divMsg").html("<font color=blue>Record saved successfully.</font>");
}
else {
record.html(returnText);
$("#divMsg").html("<font color=red>Record not saved successfully.</font>");
}
});
});
См. Http://stackoverflow.com/questions/423294/best-way-to-parse-json-data-into-a-asp-net-object для обсуждения синтаксического анализа данных JSON в .NET-объектах. –