Ajax and WebMethod Function are not in sync.
Ignoring the json input and testing if the string gets past gives this error:
Here is my Webmethod and we are ignoring mo, dy and yr as a json input:Error Code:[object Object] Status: 401 Ex: Unauthorized
This is my Ajax call. I have the exact same code in C# and it works as prescribed:Code:Imports System.IO Imports System.Web.Services Public Class _Default Inherits Page <WebMethod()> Public Shared Function GetDate(mo As Integer, dy As Integer, yr As Integer) As String Return "Test" End Function End Class
Code:<script type="text/javascript" src="~/jquery=1.10.2.js"></script> <script type="text/javascript"> $(document).ready(function () { $("#<%= Button1.ClientID %>").click(function () { var mo1 = $("#<%= TextBox1.ClientID %>").val(); var dy1 = $("#<%= TextBox2.ClientID %>").val(); var yr1 = $("#<%= TextBox3.ClientID %>").val(); var data = { mo: mo1, dy: dy1, yr: yr1 }; var json1 = JSON.stringify(data); $.ajax ({ type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", data: json1, url: "Default.aspx/GetDate", success: function (result) { $("#<%= TextBox4.ClientID %>").val(result.d); }, error: function (status, ex) { alert("Error Code:" + status + "Status: " + status.status + " Ex: " + status.statusText); } }); return false; }); }); </script>


Reply With Quote

