码迷,mamicode.com
首页 > Web开发 > 详细

ajax从asp后台获取数据

时间:2014-05-02 05:36:20      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   tar   

 

1.前台

  

bubuko.com,布布扣
$.ajax({
            //url: "demo/data/taskTree.txt",
            url: "GanttChart.aspx?taskList=1" ,
            cache: false,
            success: function (text) {
                var data = mini.decode(text);

                gantt.loadTasks(data);

                gantt.unmask();

                //折叠全部
                //gantt.collapseAll();
            }
        });
bubuko.com,布布扣

 

2.后台

 

1
2
3
4
if (Request.QueryString["taskList" ] != null)
            {
                GetTaskList();
            }

  

bubuko.com,布布扣
 StringBuilder taskStr = new StringBuilder ( "[");
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                string strSQL = @"select * from Tasks order by OrderNumber" ;
                //SqlCommand cmd = new SqlCommand(strSQL, conn);
                //SqlDataReader rdr = cmd.ExecuteReader();
                SqlDataAdapter myda = new SqlDataAdapter(strSQL, conn);
                DataSet myds = new DataSet();
                myda.Fill(myds);
                DataTable tb = myds.Tables[0];
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    DataRow row = tb.Rows[i];
                    int UID = int .Parse(row[ "OrderNumber"].ToString());
                    string taksName = row["Title" ].ToString();
                    DateTime StartDate = DateTime .Parse(row[ "StartDate"].ToString());
                    DateTime DueDate = DateTime .Parse(row[ "DueDate"].ToString());
                    TimeSpan ts = DueDate.Subtract(StartDate);
                    int FatherTask = int .Parse(row[ "FatherTask"].ToString());
                    int datelenth = ts.Days;
                    taskStr.Append( "{" );
                    taskStr.Append( "‘UID‘: ‘" + UID + "‘," );
                    taskStr.Append( "‘Name‘: ‘" + taksName + "‘," );
                    taskStr.Append( "‘Duration‘: " + datelenth + "," );
                    taskStr.Append( "‘Start‘: ‘" + StartDate.ToString() + ":T00:00:00" + "‘,");
                    taskStr.Append( "‘Finish‘: ‘" + DueDate.ToString() + ":T00:00:00" + "‘,");

                    taskStr.Append( "‘PercentComplete‘: " + 0 + "," );
                    if (FatherTask == -1)
                        taskStr.Append( "‘Summary‘: " + 1 + "," );
                    else
                        taskStr.Append( "‘Summary‘: " + 0 + "," );
                    taskStr.Append( "‘Critical‘: " + 1 + "," );
                    taskStr.Append( "‘Milestone‘: " + 0 + "," );
                    taskStr.Append( "‘PredecessorLink‘: 0," );
                    taskStr.Append( "‘ParentTaskUID‘: " + FatherTask + "," );
                    taskStr.Append( "}" );
                    if (i != tb.Rows.Count - 1)
                        taskStr.Append( "," );
                }
                taskStr.Append( "]" );
            }
            Response.Write(taskStr.ToString());
            Response.End();
bubuko.com,布布扣

 

ajax从asp后台获取数据,布布扣,bubuko.com

ajax从asp后台获取数据

标签:style   blog   class   code   java   tar   

原文地址:http://www.cnblogs.com/yixiaozi/p/3703619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!