0

Expecting

What will be the value in the textbox that value should be sent to the backend? I think the issue with the call, but I don't where it is

Javascript

function employeeLeavesList() {
                        var emp = {}
                        emp.EMPID = $("#employid").val();
                        alert(emp.EMPID);
                        $.ajax({
                            type:'POST',
                            url: 'service.asmx/employee_leaveslist',
                            data: JSON.stringify(emp),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (data) {}
                        });

                    }

class.cs

public class emp
{
    public string EMPID { get; set; }
}

webmethod.asmx.cs

[WebMethod]
        public void employee_leaveslist()
        {
            emp emp = new emp();
            List<employee_leave_list> list = new List<employee_leave_list>();
            SqlConnection connection = new SqlConnection("Data Source = Champ; Initial Catalog = sample; Integrated Security = True");
            SqlCommand cmd = new SqlCommand("select emp_id,leaves_form, leaves_upto, leave_type, description, status, no_of_leaves from leaverequest where emp_id = '" + emp.EMPID + "' ", connection);
            cmd.CommandType = CommandType.Text;
            connection.Open();
            SqlDataReader idr = cmd.ExecuteReader();
            connection.Close();

        }
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43

1 Answers1

0

First, modify the 'data' parameter of your $.ajax() call as below,

data: { empid : $('#employid').val() },

Then, modify the first line of webmethod employee_leaveslist(),

emp emp = new emp(){ EMPID  = (string)Request.Form["empid"] };
as-if-i-code
  • 2,103
  • 1
  • 10
  • 19