I am creating the following JSON object
$("#btnSubmit").click(function () {
var poll = { 'q': $('#txtQuestion').val(), 'a': [] };
for (i = 1; i < counter; i++) {
var a = $('#txtAnswer_' + i).val();
poll.a.push(a);
}
$.ajax({
type: 'POST',
url: "../_ws/Polls.asmx",
data: JSON.stringify(poll),
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});
});
basically, this retreives a question textbox’s value and answers textboxes (created on the fly) of a poll. The result is a ‘poll’ object.
I want to send this object to a webservice as seen above. No problems up until here. My question is how do I retreive this json object and process it in a function in my web service?
<WebMethod()> _
<ScriptMethod()>
Public Function AddPoll(**??? as ???**) As String
End Function
I would be grateful if anyone could help.
If I understand correctly,
pollwill end up looking like this?If so, a simple method declaration you could use would be something like:
If you wanted something more precise, you could build up your own set of matching type:
You’d need to also change your jQuery data parameter to group that data under the single variable also:
More on that here: http://encosia.com/using-complex-types-to-make-calling-services-less-complex/