Results 1 to 4 of 4

Thread: Ajax and WebMethod Function are not in sync

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    Ajax and WebMethod Function are not in sync

    Ajax and WebMethod Function are not in sync.

    Ignoring the json input and testing if the string gets past gives this error:

    Error Code:[object Object] Status: 401 Ex: Unauthorized
    Here is my Webmethod and we are ignoring mo, dy and yr as a json input:
    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
    This is my Ajax call. I have the exact same code in C# and it works as prescribed:

    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>
    Last edited by Philosophaie; Apr 28th, 2017 at 12:43 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width