直接上代码: $(document).ready(function() {
        $.ajax({
            cache: false,  
                   url: 'data.xml',
            dataType: 'xml',
            type: 'GET',
            timeout: 1000,
            error: function(xml) {
                alert("加载数据文件失败...");
            },
            success: function(xml) {
           
                var g = new Gantt(document.getElementById("GanttChart"));
                $(xml).find("taskList").each(function(i) {                    var _Id = $(this).children("id");
                    var _from = $(this).children("from");
                    var _to = $(this).children("to");
                    var _topra = $(this).children("topra");
                    var _task = $(this).children("task");
                    var _resource = $(this).children("resource");
                    var _progress = $(this).children("progress");
                    var _notes = $(this).children("notes");
                    var _noworkday = $(this).children("noworkday");
                    
                    //获取id节点的文本值;
                                   var id = _Id.text();
                    var from = _from.text();
                    var to = _to.text();
                    var topra = _topra.text();
                    var task = _task.text();
                    var resource = _resource.text();
                    var progress = _progress.text();
                    var notes = _notes.text();
                    var noworkday = _noworkday.text();                    g.AddTaskDetail(new Task(from, to,topra,task, resource, progress, notes,noworkday));                })
                g.Draw();
            }
        });现在是读取的xml文件的数据,怎样直接从数据库中读取啊,还得循环把值赋给这个方法...

解决方案 »

  1.   

    Jquery有直接解析XML的方法。不需要自己遍历吧。
    或者用Extjs
      

  2.   

    如果是asp.net的话。直接获取整个页面的值。处理页面用数据控件绑定输出值就可以啦!
      

  3.   

    是asp.net ,以前是思路是把数据查询输出到xml,然后从xml中获取数据实现绑定,现在想直接从数据库中获取数据,把值赋给js中的方法...数据最终还是通过js操作的...
      

  4.   

    要是这样,感觉还不如从xml中读取了...不过还是要谢谢
      

  5.   

    我知道啊。我的意思是直接返回给AJAX的数据就是HTML了。而HTML就是在处理的页面中输出好了你要的结果!