Please see the JavaScript code below:
function SaveOrReview(Me)
{
var frm = document.forms[0];
var arrayDisposals;
var intCount;
var arrayDisposals = new Array();
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox" && frm.elements[i].name.substr(0, 3) == "Del") {
arrayDisposals.push(frm.elements[i].id)
}
}
$.ajax({
type: "POST",
url: "PrimaryNominalAjax.aspx/AddDisposalList",
data: '{str: "' + arrayDisposals + '", strCon: "' + $("#<%=fieldGenieConnectionString.ClientID%>")[0].value + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess(),
failure: function (response) {
alert('there was an error updating a MOPI grade')
}
});
function OnSuccess() {
return function (response) {
alert('succeeded')
}
}
}
and the server side code below:
<System.Web.Services.WebMethod()> _
Public Shared Function AddDisposalList(ByVal str() as string, ByVal strCon As String) As String
msgbox("test")
end function
The webmethod is not called. If I remove the array argument from the JavaScript call and the string array from the calling JavaScript then it works i.e. the message box display. Therefore my question is how do you pass an array over AJAX.
I have looked at a few other questions on here but they relate to PHP and Java, rather than VB.NET.
data: '{str: "' + JSON.stringify(arrayDisposals) + '", strCon: "' + $("#<%=fieldGenieConnectionString.ClientID%>")[0].value + '"}', but i don't know how you get it in server side with VB.NET. Get array like string and parse it