Reputation: 1187
I post data to a aspx page via ajax, and now i don't know how to read it. I just need to take the strings that are passed via JSON and assign them to certain variables and manipulate the variables in the .aspx file. How do I do this?
Here is the jquery:
var ceSaveDatea = {};
ceSaveDatea.one = requestNumber;
ceSaveDatea.two = itemTypeID;
ceSaveDatea.three = servicesRequired;
ceSaveDatea.four = otherComments;
ceSaveDatea.five = suggestedReplacements;
ceSaveDatea.six = internalTestingRequired;
ceSaveDatea.seven = externalTestingRequired;
ceSaveDatea.eight = ceGeneralComments;
/*
var url = "../ajaxURLs/ComponentEngineering.aspx?requestNumber=" + requestNumber + "&itemTypeID=" + itemTypeID + "&servicesRequired=" + servicesRequired + "&otherComments=" + otherComments + "&suggestedReplacements=" + suggestedReplacements + "&internalTestingRequired=" + internalTestingRequired + "&externalTestingRequired=" + externalTestingRequired + "&ceGeneralComments=" + ceGeneralComments;
var encodedURL = EncodeURL(url);
*/
$.ajax({
type: "POST",
url: "/ajaxURLs/ComponentEngineering.aspx",
data: JSON.stringify(ceSaveDatea),
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {
alert(data);
if (data != '')
$('#checkboxContainerDiv').html(data);
},
error: function(msg) {
alert('error');
}
});
Then I just need to take this information and convert it on the ComponentEngineer.aspx page. It is not a web service.
Thanks!
Upvotes: 0
Views: 584
Reputation: 684
The following code should do what you need:
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<object, object> jsonLookup = ((Dictionary<object, object>)serializer.Deserialize<Dictionary<object, object>>(jsonSource));
The 'jsonSource' passed into the Deserialize method is your JSON string.
Prerequisites are:
Upvotes: 0
Reputation: 10984
If you want to handle JSON in your C# code, I strongly encourage you to go explore JSON.NET
Upvotes: 1