Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
Hi,
I am getting this error when passing parameter to an ajax call

This is my html page:
script type="text/javascript" type="text/javascript">
       $(function () {
            $("#theList").removeData();
           $("#btnSearchAvailRoom").on("click", function () {
                 Greating();
            });
        });

       function Greating() {
           var checkin =$("#datepickercheckin").val();
           var checkout = $("#datepickercheckout").val();
           var query = "CarService.asmx/GetAllProducts";
           $.ajax({
               type: "POST",
               url: query,
               data: JSON.stringify({ checkindate: checkin, checkoutdate: checkout }),

                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var productt = response.d;
                    alert(data);
                    $.each(productt, function (index, product) {

                        $("#theList").append("  " + product.name + " " + product.descr + "");
                    });

                    console.log(response);
                },

                error: function (response) {
                    $("#theList").append("error");

                    console.log(response);
                }
            });
        }
  </script>

</head>
<body>
     <div>
         <fieldset>
            <legend>Search Room</legend>
            <fieldset>
                <legend>Show By </legend>
                <p>
                    Checkin:
                <input type="text" id="datepickercheckin" class="datepicker" />
                </p>
                <p>
                    Checkout:
                    <input type="text" id="datepickercheckout" class="datepicker" />
                </p>

            </fieldset>
            <br /><input type="button" id="btnSearchAvailRoom" value="Search Room" />
        </fieldset>
         </div>
    <div data-role="content">
        <ul id="theList" data-role="listview" data-inset="true" data-filter="true">
        </ul>
    </div>
</body>
</html>

And this the code behind my webservice CarService.cs:

public List<product> GetAllProducts(string Checkin, string Checkout)
    {
        List<product> lstproducts = new List<product>();

        DateTime CheckinDate = DateTime.ParseExact(Checkin, "mm/dd/yyyy", CultureInfo.InvariantCulture.DateTimeFormat);
        DateTime CheckoutDate = DateTime.ParseExact(Checkout, "mm/dd/yyyy", CultureInfo.InvariantCulture.DateTimeFormat);
        using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.GetConnection(), "GetProducts", CheckinDate, CheckoutDate))
        {
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    product _product = new product();
                    _product.name = Convert.ToString(dr["name"]);
                    _product.img = Convert.ToString(dr["Image"]);
                    _product.descr = Convert.ToString(dr["Description"]);
                    lstproducts.Add(_product);

                }
            }
            return lstproducts;
        }
    }
 Can you help what is wrong?
Posted

1 solution

I think the error message is quite clear. However, you have not specified which parameters are missing. Usually, you would get as the part of error message.

Are checkindate and checkoutdate the only two parameters your web service expects? I doubt that.
 
Share this answer
 
Comments
El Dev 16-Nov-14 6:28am    
what is the difference between consuming a webservice and calling aspx file.
In this exemple when calling an aspx file it is working but when consuming a webservice it is raising an error:
Unknown web method SaveData. Parameter name: methodName

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";
//var query = "CarService.asmx/SaveData";
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: query,
//data: '{ Name: "Daniel", SName: "Ndekezi" }',
data: '{ checkindate: "'+ checkin + '", checkoutdate: "'+ checkout +'" }',
dataType: "json",
success: function (data) {
$('#divtxt').text(data.d);
},
error: function (result) {
alert("error");
}
});
}
and this my code behind in the webservice or the aspx.cs file:
I am using the same method:
[WebMethod]
public static string SaveData(string checkindate, string checkoutdate)
{
string str = checkindate + " " + checkoutdate;
return str;
}
can u tell me the difference

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900