JQuery DataTables 插件问题
我遇到了以下代码的奇怪问题
$(document).ready(function() {
$('#example').dataTable({
"bProcessing":true,
"sAjaxSource":'http://localhost/utcms/json_source2.txt'});
});
});
如果我在 safari 中运行页面,则此代码将数据加载到表中没有问题。我的问题是,如果我通过 django 使用 render_to_response 运行同一页面,我得到的只是处理标志,没有数据。调试时它只是说:无法加载资源:已取消。
这不是无法找到源文件的问题,我还排除了由于渲染页面和中断获取过程而导致问题的可能性。我一定是在数据表设置中遗漏了一些东西。奇怪的是,它可以在静态页面上工作,但不能在 django 渲染的页面上工作,即使它看到该文件,否则它会在调试时为该文件生成 404。
欢迎任何建议
干杯
克里斯
PS:我是 JQuery 和 DataTables 的新手
I have encountered a strange problem with the following code
$(document).ready(function() {
$('#example').dataTable({
"bProcessing":true,
"sAjaxSource":'http://localhost/utcms/json_source2.txt'});
});
});
This code loads the data into the table if I run the page in safari no problem. My issue is that if I run the same page through django with a render_to_response all I get is the processing sign no data. upon debugging it simply says: Failed to load resource: Cancelled.
Its not an issue with not being able to find the source file, I've also discounted the possibility of an issue resulting from rendering the page and disrupting the fetch process. I must be missing something in datatable setup. its strange that it works on a static page but not on a django rendered page even though it sees the file otherwise it would generate a 404 for that file on debug.
Any suggestions would be welcome
Cheers
Chris
PS: I am new to JQuery and DataTables
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果其他人也遇到类似的困难,我可以解决这个问题。它并不优雅,但很有效。
从 JQuery 请求函数获取 JSON 响应并解析它并将其作为数组加载到表中。正如我所说,它并不优雅,但很有效。
I have a work around if anyone else is having similar difficulty. It ain't elegant but it works.
Grab the JSON response from the JQuery request function and parse it and load it into the table as an Array. As I say it isn't elegant but it works.
您应该尝试向 render_to_response 添加 mimetype 选项 :
I你像我一样使用很多 Jquery DataTables 及其服务器端处理功能,你真的应该检查 这些 Django 实用程序。安装后,一切都归结为使用几行代码并向其传递一个查询集。
You should try to add a mimetype option to render_to_response :
I you use a lot Jquery DataTables and its server-side processing feature as I do too, you really should check these utilities for Django. When installed, it all boils down to use a few lines of code and passing it a queryset.