Click here to Skip to main content
14,825,149 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hi all
please help me
it's my HTML code:
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <script src="content/js/jquery-2.1.4.js"></script>
    <title></title>
</head>
<body>
    <script type="text/javascript">
        $("document").ready(
        
            $.ajax(
                {
                    type: "POST",
                    url: "test.asmx/sending",
                    data:"'st:','sultan'",
                    contentType: "application/json",
                    dataType: "json",
                    success: accessfn,
                    error: errfn
                }
                )
               
        )
        function accessfn(result) {
            alert(result.d);
        }
        function errfn(result) {
            alert(result.d);
        }

    </script>
    <form id="form1"  runat="server">
            "<asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/test.asmx" />
            </Services>
        </asp:ScriptManager>"
        </form>
        </body>
</html>

and it's my asp.net asmx file:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace didantest
{
    /// 
    /// Summary description for didan
    /// 
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class didan : System.Web.Services.WebService
    {
        [ScriptMethod]
        [WebMethod]
        public string sending(string st)
        {
            st = st + "bingo";
            return st;
        }
    }
}

and result.d is "undefined"
why it's not working?what's the problem?
thanks
Posted
Comments
Kornfeld Eliyahu Peter 4-Aug-15 9:12am
   
Debug the server side!
mohamadMahmodi 4-Aug-15 13:22pm
   
i made a http://localhost asp.net website format project and it insert test.cs in App_code folder, but create test.asmx in root without any sub!
F-ES Sitecore 4-Aug-15 9:21am
   
Use the browser tools to debug the network traffic. However from a casual glance it looks like your data is wrong, should be data:"{'st':'sultan'}", There might be other problems though, if there are see above link.
Praveen Kumar Upadhyay 4-Aug-15 9:21am
   
Put a debug point and see if debugger is reaching out to your service. Check what value you get for st in service.
mohamadMahmodi 4-Aug-15 13:26pm
   
when i debug project in test.asmx page ,it want me invoke a value, it worked but it is in server side and not any relat to HTML ajax
mohamadMahmodi 4-Aug-15 10:35am
   
thanks,i try it
ZurdoDev 4-Aug-15 10:46am
   
I'd suggest doing it this way:
success: function (result, textStatus, jqXHR) {
accessfn(result);
}
mohamadMahmodi 4-Aug-15 13:46pm
   
I've used above all but not working yet

1 solution

thanks all,it's solved:
HTML
<script type="text/javascript">
        $("document").ready(
        
            $.ajax(
                {
                    type: "POST",
                    url: "test.asmx/sending",
                    data: {st:'sultan'},
                    dataType: "text",
                    success: accessfn,
                    error: errfn
                }
                
                )
               
        )
        function accessfn(result) {
            $("#mess").append(result);
        }
        function errfn(result) {
            $("#mess").append(result);

        }

    </script>

and:
C#
public string sending(string st)
        {
            st = st + "bingo";
            return st;
        }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900