Friday, September 25, 2015

Calling webmethod in Jquery

SELECT  n
FROM EMP o
WHERE (SELECT count(*) FROM EMP i WHERE i.n < o.n) < 5
[System.Web.Services.WebMethod]
    public static string Emp (int num, string  Name)
    {
        Emp ObjEmp = new Emp();
        ObjEmp.AddItem(n, N);
        return "Add";

    }


Call below jqery code to insert the employee data by calling the web method which has written on code behind window;

jQuery.ajax({
            url: 'Default.aspx/Emp',
            type: "POST",
            data: "{'n' : " + n + ",'N':" + N + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            beforeSend: function () {
                alert("Start");
            },
            success: function (data) {
                alert("a");
            },
            failure: function (msg) { alert("Sorry "); }
        });