what is the difference between consuming a webservice and calling aspx file.
In this exemple when calling an Default2.aspx file it is working but when consuming a webservice CarService.asmx it is raising an error:
Unknown web method SaveData. Parameter name: methodName
As u can see I have comment it out the calling of the webservice var query = "CarService.asmx/SaveData";because it it raising the error mentioned above when uncomment.
This is my code:
$(function () {
var checkin = $("#datepickercheckin").val();
var checkout = $("#datepickercheckout").val();
$('#btnSearchAvailRoom').on("click", function () {
Greating();
});
});
function Greating() {
var query = "Default2.aspx/SaveData";
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: query,
data: '{ checkindate: "'+ checkin + '", checkoutdate: "'+ checkout +'" }',
dataType: "json",
success: function (data) {
$('#divtxt').text(data.d);
},
error: function (result) {
alert("error");
}
});
}
and I am using the same code for both files webservice or the aspx.cs file, in the code behind:
[WebMethod]
public static string SaveData(string checkindate, string checkoutdate)
{
string str = checkindate + " " + checkoutdate;
return str;
}
can u tell me the difference and Why I am getting that error and how to resolve it