ServerSide data: POST data to ASMX webService using JSON

ServerSide data: POST data to ASMX webService using JSON

jbrownwkejbrownwke Posts: 1Questions: 0Answers: 0
edited March 2014 in General
Hello All,

I'm trying to get data from server using POST and JSON data formatting.

The ASMX webService I have is this one:

[code]

Imports System.Web.Services
Imports System.ComponentModel
Imports System.Web.Script.Services

_
_
_
_
Public Class GetData
Inherits System.Web.Services.WebService

_
Public Function GetData(ByVal Variable1 As String)

Return 1

End Function

End Class

[/code]

The JavaScript dataTable initialization is this one:

[code]


$('#' + this._selector).dataTable({
'aoColumnDefs': this.get_dataTableColumns(),
'bScrollCollapse': true,
'sScrollY': '200px',
'paging': false,
'sAjaxSource': '../A3DataTableUserLayer/A3DataTableService.asmx/GetData',
'bServerSide':true,
'fnServerData': function (sSource, aoData, fnCallback, oSettings) {
$.ajax({
type: 'POST',
data: aoData
dataType: 'json',
url: sSource,
contentType: 'application/json',
success: function (json) {
fnCallback(json)
},
error: function (jqXHR, textStatus, errorThrown) {
debugger;
}
});
}
});

[/code]

When I call to ASMX webService, using Fiddler, I can see that post data (aoData) is not a JSON object, but a string (like this):

[code]
sEcho=1&iColumns=6&sColumns=%2C%2C%2C%2C%2C&iDisplayStart=0&iDisplayLength=-1&mDataProp_0=0&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=1&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=2&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=true&mDataProp_3=3&sSearch_3=&bRegex_3=false&bSearchable_3=true&bSortable_3=true&mDataProp_4=4&sSearch_4=&bRegex_4=false&bSearchable_4=true&bSortable_4=true&mDataProp_5=5&sSearch_5=&bRegex_5=false&bSearchable_5=true&bSortable_5=true&iSortCol_0=0&sSortDir_0=asc&sSearch=&bRegex=false&iSortingCols=1
[/code]

And, of course, the ASMX webService is crashing because he expects a JSON object.

If I change $.Ajax data parameter to something like this:

"{'Variable1':'1', 'Variable2':'2'}"

.... I can see in Fiddler this string as a JSON object and the webService call responses correctly.

¿Somebody knows why?
This discussion has been closed.