I am new to jQuery Ajax. I need your help. I want to display one text next to a span element. I already made a link to some topics, but I canβt resolve it.
Here is my error in firebug (new lines and padding added)
{"Message":"Invalid web service call, missing value for parameter: \u0027haha\u0027.", "StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters) at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters) at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams) at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)", "ExceptionType":"System.InvalidOperationException"}
In aspx
<asp:TextBox ID="txtNoiDung" runat="server" TextMode="MultiLine" CssClass="txtNoiDung"></asp:TextBox><span id="vltxtNoiDung"></span>
In code
[WebMethod()] public static string test1cai(string haha) { return haha; }
In javascript
$(".txtNoiDung").focusout(function () { var dataToSend = { names: $(this).val() }; $.ajax({ type: "POST", url: "QuanLyTin.aspx/test1cai", data: JSON.stringify(dataToSend), contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $("#vltxtNoiDung").text(msg.d) }, error: function (xhr, reason, ex) { alert(reason); } }); });
Thanks in advance!
source share