javascript 数据表中的 sAjaxSource 参数究竟是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22194997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:39:55  来源:igfitidea点击:

What exactly is the sAjaxSource parameter in datatables?

javascriptjqueryajaxjsonjquery-datatables

提问by Marco Prins

According to datatables website,

根据数据表网站

sAjaxSource
You can instruct DataTables to load data from an external source using this parameter (use aData if you want to pass data in you already have). Simply provide a url a JSON object can be obtained from. This object must include the parameter 'aaData' which is the data source for the table.

sAjaxSource
您可以使用此参数指示 DataTables 从外部源加载数据(如果您想传递已有的数据,请使用 aData)。只需提供一个可以从中获取 JSON 对象的 url。该对象必须包含参数“aaData”,它是表的数据源。

Now, to me (an amateur with Ajax and JSON), this is gibberish.

现在,对我(Ajax 和 JSON 的业余爱好者)来说,这是胡言乱语。

I want my datatable to paginate, and load new entries using Ajax each time the table is re-sorted or the next page is chosen (instead of loading all entries up front)

我希望我的数据表进行分页,并在每次重新排序表或选择下一页时使用 Ajax 加载新条目(而不是预先加载所有条目)

Apparently this "url a JSON object can be obtained from" is needed if I want to set the bServerSideoption to true

显然,如果我想将该bServerSide选项设置为 true,则需要此“可以从中获取 JSON 对象的 url”

Is there anyone that can explain this concept to me?

有没有人可以向我解释这个概念?

采纳答案by Lukasz Koziara

In server-side processing you can choose either of two ways:

在服务器端处理中,您可以选择以下两种方式之一:

  1. Serve JSON from the same URL, which you use to show HTML page with a table (page with table is on www.example.com/tableand AJAX call to www.example.com/?sEcho=1&andOtherParametersHere) - you do not need specify sAjaxSource, because datatable's script joins the parameters to the existing URL.

  2. Serve JSON from URL that is different from one you use to show HTML page with table (so page with table is on www.example.com/tableand AJAX call to www.another.com/?sEcho=1&andOtherParametersHere) - you must specify sAjaxSourceto www.another.com.

  1. 从相同的 URL 提供 JSON,您用来显示带有表格的 HTML 页面(带有表格的页面www.example.com/table和 AJAX 调用www.example.com/?sEcho=1&andOtherParametersHere) - 您不需要指定sAjaxSource,因为数据表的脚本将参数连接到现有的 URL。

  2. 从 URL 提供 JSON,该 URL 不同于您用来显示带有表格的 HTML 页面的 URL(因此带有表格的页面打开www.example.com/table并且 AJAX 调用www.another.com/?sEcho=1&andOtherParametersHere) - 您必须指定sAjaxSourceto www.another.com

回答by valentin

Simply put, it's the URL that returns your DataTables content that you want to display (your data source for server-side processing).

简而言之,它是返回要显示的 DataTables 内容的 URL(用于服务器端处理的数据源)。

If you need more details, there are plenty of links in the other replies that detail it.

如果您需要更多详细信息,其他回复中有很多详细链接。