Jquery Ajax and WebService


I have Web Services that get all data from SQL server and I create HTML table to dispaly all data using Jqurry Ajax but I have problem with ajax. can any one help me


  $(document).ready(function () {
      $("#contant_hr").append('<table id="ResultsTable" class="DepartmentTable"><tr><th>Department ID</th><th>Name</th><th>Group Name</th><th>Modified Date</th></tr>');
          type: "POST",
          contentType: "application/json; charset=utf-8",
          url: "Department_Service.asmx/GetAllDepartments",
          dataType: "json",
          success: function (msg) {
              var c = eval(msg.d);
              for (var i in c) {
                  $("#ResultsTable tr:last").after("<tr><td>" + c[i][0] + "</td><td>" + c[i][1] + "</td><td>" + "</td><td>" + c[i][2] + "</td><td>" + c[i][3] + "</td></tr>");



[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetAllDepartments() {
SqlConnection conn = new SqlConnection(“Data Source=ABDALLA-HP\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True;”);

    string sqlstring   = "SELECT DepartmentID, Name, GroupName, ModifiedDate FROM  HumanResources.Department";
    SqlCommand comm = new SqlCommand(sqlstring,conn);

    DataSet dataset = new DataSet();
    SqlDataAdapter adapter = new SqlDataAdapter(comm);
    adapter.Fill(dataset, "reading");


    //creating Array 
    string[][] jaggedArray = new string[dataset.Tables[0].Rows.Count][];
    int i = 0;
    foreach (DataRow rs in dataset.Tables[0].Rows)
        jaggedArray[i] = new string[] { rs["DepartmentID"].ToString(), rs["Name"].ToString(), rs["GroupName"].ToString(), rs["ModifiedDate"].ToString() };
        i = i + 1;


    //return JSOM data
    JavaScriptSerializer js = new JavaScriptSerializer();
    string strJSON = js.Serialize(jaggedArray);
    return strJSON;   


Well, what exactly is it doing? I have never used a web method for returning jSON to jQuery before. Usually just a call to an aspx page with the correct parameters if any, which formats the response as json. If you browse directly from your browser to Department_Service.asmx/GetAllDepartments, does it load the data? I dout it, as you need to interact differently with a webservice.

Change it to use an aspx page and see if that works

you can make an AJAX request like any other requests:

$.ajax( {
success:function(data) {