I'm trying to reload my table using the on-the-fly ajax method for changing the URL. I have to filter the results by a search field that is manually made.
我正在尝试使用动态ajax方法重新加载表,以更改URL。我必须通过手工创建的搜索字段来过滤结果。
According to the API I can use the url()
method, but it's not working. I'm using DataTables 1.10.2 downloaded yesterday.
根据API,我可以使用url()方法,但它不能工作。我使用的是昨天下载的DataTables 1.10.2。
This is my code:
这是我的代码:
dTable.ajax.url('newurl.php').load();
The error I get from the console is:
我从控制台得到的错误是:
TypeError: Cannot read property 'url' of undefined
类型错误:无法读取未定义的属性“url”
But if I do a console.log
for the dTable object I get the object back. So it's there.
但如果我做一个控制台。对dTable对象的日志,我将该对象取回。所以它的存在。
2 个解决方案
#1
4
Evidently DataTables requires the api()
function to be called before anything. I personally never found this in the documentation anywhere and only on their forum.
显然,datatable要求在任何事情之前调用api()函数。我个人从未在任何地方的文档中发现过这一点,而且只在他们的论坛上发现过。
So the final command needed to be:
所以最终的命令必须是:
dTable.api().ajax.url('newurl.php').load();
This now allows this function to succeed.
这就允许这个函数成功。
#2
0
dTable.ajax.url('newurl.php').load();
... is now actually correct in DataTables v1.10, as documented here:
…现在在DataTables v1.10中是正确的,如本文所示:
https://datatables.net/reference/api/ajax.url%28%29
https://datatables.net/reference/api/ajax.url%28%29
and is intended for the same purpose as you have in mind: changing the data source location (such as adding custom search parameters to the URL) on the fly.
它的目的与您所想的相同:动态地更改数据源位置(例如向URL添加自定义搜索参数)。
I have implemented this in my own app, for on-the-fly custom results filtering, and it's working excellently.
我已经在我自己的应用中实现了这一点,用于动态自定义结果过滤,它工作得很出色。
#1
4
Evidently DataTables requires the api()
function to be called before anything. I personally never found this in the documentation anywhere and only on their forum.
显然,datatable要求在任何事情之前调用api()函数。我个人从未在任何地方的文档中发现过这一点,而且只在他们的论坛上发现过。
So the final command needed to be:
所以最终的命令必须是:
dTable.api().ajax.url('newurl.php').load();
This now allows this function to succeed.
这就允许这个函数成功。
#2
0
dTable.ajax.url('newurl.php').load();
... is now actually correct in DataTables v1.10, as documented here:
…现在在DataTables v1.10中是正确的,如本文所示:
https://datatables.net/reference/api/ajax.url%28%29
https://datatables.net/reference/api/ajax.url%28%29
and is intended for the same purpose as you have in mind: changing the data source location (such as adding custom search parameters to the URL) on the fly.
它的目的与您所想的相同:动态地更改数据源位置(例如向URL添加自定义搜索参数)。
I have implemented this in my own app, for on-the-fly custom results filtering, and it's working excellently.
我已经在我自己的应用中实现了这一点,用于动态自定义结果过滤,它工作得很出色。