Question

I have following webservice:

[webmethod]
public string MakeReservation(?? PassengersInfo)//what data type use for PassengerInfo 
{
}

and in javascript I have following code.

 var ResultInfo = new Array();
    $("#GrdPassengerInformationMakeReservation").find('tr:not(:first)').each(function() {
        var Info = new Array();
        Info.push($(this).find('td:eq(1)').text());
        Info.push(($(this).find('td:eq(2)')).find('select').val());
        Info.push(($(this).find('td:eq(3)')).find('input').val());
        Info.push(($(this).find('td:eq(4)')).find('input').val());
        Info.push(($(this).find('td:eq(5)')).find('select').val());
        Info.push(($(this).find('td:eq(6)')).find('input').val());

        ResultInfo.push(Info);

    })
$.ajax(
    { url: "Ajaxes/Reservation.asmx/MakeReservation",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        type: "POST",
        data: "{'PassengersInfo':'" + ResultInfo + "'}",
        async: false,
        success: function(data) {

        }
});

I want to pass ResultInfo to webservice. What data type should I use in my webservice?

Was it helpful?

Solution

Since Info is an Array, use Array at the server side. But in that case you can pass the Info as such instead of sending it inside another array which is again wrapper into an object in your ajax post method, i.e. data: Info.
Or you can use ArrayList since ResultInfo contains arrays (in this case only one array). In that case sent the ajax post with data: ResultInfo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top