1

I have problem while using AJAX in ASP.Net.getName not fired.. anything wrong.? Please find the below samples and suggest me.

 ` <input type="button" value="Bulk Save" id="savebtn" />`

$("#savebtn").click(function () {
            var firstName = "SAmple";
            var lastName = "Name";
            var param = { fs: firstName, ls: lastName };
            $.ajax({
                type: "POST",
                url: '<%=ResolveUrl("~/Features.aspx/getName")%>',
                data:JSON.stringify(param),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                //async:true
            })
        });

    [WebMethod]
    public static void getName(string fs, string ls)
    {

    }
Redlab
  • 3,110
  • 19
  • 17
Shanmugaraja_K
  • 1,914
  • 3
  • 13
  • 25
  • Have you tried add [HttpPost] above your getname() method? – kgzdev Jan 25 '17 at 13:30
  • What error do you get in the browser console? – Andrei Filimon Jan 25 '17 at 13:30
  • @IkramTurgunbaev That's not necessary. That would be for MVC or Web API, but this is Web Forms's WebMethods. Different. – mason Jan 25 '17 at 15:33
  • Check here: [http://stackoverflow.com/questions/6928533/calling-a-webmethod-with-jquery-in-asp-net-webforms](http://stackoverflow.com/questions/6928533/calling-a-webmethod-with-jquery-in-asp-net-webforms) – Khaled Jan 25 '17 at 16:52
  • Check here: http://stackoverflow.com/questions/6928533/calling-a-webmethod-with-jquery-in-asp-net-webforms – Khaled Jan 25 '17 at 16:53
  • Have you tried this? http://stackoverflow.com/questions/6928533/calling-a-webmethod-with-jquery-in-asp-net-webforms – Khaled Jan 25 '17 at 17:00

1 Answers1

1

if you are using a separate js file for your ajax code, then you can use this

url:'http://domain_name/controller_name/method'

otherwise

url: "Features.aspx/getName"
  • Could you also explain why? Thanks! – Cullub Jan 25 '17 at 15:04
  • 1
    Since it will look in root directory, it is an absolute path and it will be effective...i have tried this and it is working fine. Thank you! –  Jan 26 '17 at 04:29