locked
Call a method from server-side, but I can't get it RRS feed

  • Question

  • User1572049755 posted

    Hi all,

    Thank you for your time. I am learning how to use Ajax to call a server method and return some value. But, my test code can't return a sting. Below is my code.

    <script src="Scripts/jquery-2.1.3.js"></script>
        <script type="text/javascript">
            $(document).ready(
                function ()
                {
                    $.ajax(
                    {
                        type: "POST",
                        url: "AjaxCallWebMethod(string).aspx/ReturnString",
                        data: "firstName=Swan&lastName=W",
                        //contentType: "application/json; charset=utf-8",
                        dataType: "text",
                        success: function (data)
                        {
                            $("#Text1").html(data);
                        }
                    })
                }
                );
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="Text1" type="text" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </div>
        </form>
    [WebMethod]
            public static string ReturnString(string firstName,string lastName) 
            {
                string Text = "Hello"+firstName+lastName;
                return Text;
            }

    So, kindly provide a solution and provide me a good tutorial about how to use Ajax. Besides call method from server-side, I also want to learn how to call WebAPI, WCF...

    Please help me.

    Swan

    Sunday, May 3, 2015 11:04 PM

Answers

All replies