I am new to webservice and JSON. I am developing an application in asp.net which uses Webservices and JSON for Posting data in Ajax call to Server. In the below function PostData I am getting an error at:
data: "{" + jsonObjectName + ":" + JSON.stringify(dataToSend) + "}", as "json" is undefined.
Here dataToSend is an object which contains my data
submitType is submit button id (in page this I have two submit buttons so, I called by id)
strMessagetoShow is text to show success or failure
strMethodToCall which method is called in Webservice?
function PostData(dataToSend, submitType, strMessagetoShow, strMethodToCall, jsonObjectName) {
$.ajax({
url: window.top.GetWsUrl() + "/" + strMethodToCall,
type: "POST",
dataType: "json",
data: "{" + jsonObjectName + ":" + JSON.stringify(dataToSend) + "}",
timeout: 30000,
contentType: "application/json; charset=utf-8",
success: function (data) {
return data;
},
error: function (result) {
alert(result.status + ' ' + result.statusText);
}
});
}