0

第一次用aspx页面webmethod在asp.net中实现jQuery DataTable,这里是webmethod代码,

    [WebMethod()]
    public static List<Activity> GetJobActivity(int jobid)
    {
        try
        {
            string connectionstring = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
            SqlConnection Con = new SqlConnection(connectionstring);
            DataTable DT = new DataTable();
            List<Activity> activity = new List<Activity>();
            DataSet DS = new DataSet();
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.Connection = Con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_GetJobActivity";
                cmd.Parameters.Add("@jobid", SqlDbType.Int).Value = jobid;
                Con.Open();
                SqlDataAdapter DA = new SqlDataAdapter(cmd);
                DA.Fill(DT);
                foreach (DataRow DR in DT.Rows)
                {
                    Activity act = new Activity();
                    act.comment = DR["Comment"].ToString();
                    act.activity = DR["activity"].ToString();
                    act.emp = DR["EmpName"].ToString();
                    act.createdon = DR["Createdon"].ToString();
                    activity.Add(act);
                }
            }
            Con.Close();
            return activity;
        }
        catch (Exception ex)
        {
            throw new System.Exception("Error In Get Job Activity :" + ex.Message);
        }
    }

我尝试使用带有 Post 方法的 jquery ajax 函数获取数据,例如

        $.ajax({
            type: "POST",
            url: "ViewJob.aspx/GetJobActivity",
            data: JSON.stringify({ jobid: $("#id").val()}),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                RenderTable(response.d);
            }
        });

但它不起作用,请帮我解决这个问题。

4

0 回答 0