Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Message":"Invalid web service call, missing value for parameter: \u0027

Tags:

jquery

asp.net

I got this error when i send 2 parameter from jQuery to WebMethod and using multiple params.

{"Message":"Invalid web service call, missing value for parameter: \u0027haha\u0027.","StackTrace":"   at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n   at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

In jQuery:

$(".txtNoiDung").focusout(function () {
        $.ajax({
            type: "POST",
            url: "QuanLyTin.aspx/test1cai",
            data: JSON.stringify({ hahas: $(this).val(),tuans: "hahaha" }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $("#vltxtNoiDung").text(msg.d)
            },
            error: function (xhr, reason, ex) {
                alert(reason);
            }
        });
    });

In code behind

 [WebMethod()]
        public static string test1cai(string haha, string tuan)
        {
            return "Hi, "+haha + tuan;
        }

How can i resolve it? Thanks you guys.

like image 256
tuan.it89 Avatar asked Nov 07 '11 02:11

tuan.it89


1 Answers

Your service is accepting parameters named haha and tuan, but your JavaScript is passing in hahas and tuans. Remove the "s" from both:

data: JSON.stringify({ haha: $(this).val(),tuan: "hahaha" }),

Also, keep in mind that these parameters much match between client- and server-side with case-sensitivity.

like image 52
Dave Ward Avatar answered Oct 14 '22 05:10

Dave Ward