如何在YUI中向Django服务器发出XHRDataSource请求?

时间:2010-08-10 15:37:41

标签: javascript django yui yui-datatable yui-datasource

我正在使用post,而YUI文档示例代码无效。

YAHOO.util.Event.addListener(window,"load",function()
{

    var columnDefs = 
    [ 
        {key:"url", sortable:true, resizeable:true}, 
        {key:"title", sortable:true, resizeable:true}, 
        {key:"count", sortable:true, resizeable:true} 
    ];

    this.dataSource = new YAHOO.util.DataSource("/getallsites/");
    this.dataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
    this.dataSource.connMethodPost = true;
    this.dataSource.responseSchema = 
    {
        fields:["url","title","count"]    
    };

    this.myDataTable = new YAHOO.widget.DataTable("siteTable",columnDefs,this.dataSource,
        {initialRequest:"/getallsites/"});


});

/ getallsites /返回一个JSARRAY。在将其转换为JSON之前,我想让JSARRAY工作。 Django服务器日志甚至没有识别对/ getallsites /的请求。有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

首先,确保您在页面上包含Connection Manager实用程序。

其次,您配置它的方式,请求将转到/ getallsites // getallsites /,因此请尝试将initialRequest设置为“”。