Ajax 使用 Typo3 Extbase Controller 功能调用 Datatables Serverside

Ajax call for Datatables Serverside with Typo3 Extbase Controller function

我正在尝试使用前端插件的 Typo3 Extbase 控制器调用 Ajax 数据 table 服务器端,但无法获取 table 中的数据,而只有以下输出:

{"sEcho":0,"iTotalRecords":"6","iTotalDisplayRecords":"6","aaData":[["1","Hans","Meier","51","2011-04-13","EUR200"],["2","Frank","Heinz","45","2004-02-17","EUR60"],["3","Katrin","Kohl","35","2011-08-17","EUR1000"],["4","Werner","Pertl","39","2013-11-19","USD499"],["5","Christina","Sinn","22","2015-03-09","GBP99"],["6","Klaus","Vienna","67","1991-01-15","EUR5000"]]}

我正在使用以下视图 (list.html):

<f:layout name="Default" />
<f:section name="main">

<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Field 1</th>
            <th>Field 2</th>
            <th>Field 3</th>
            <th>Field 4</th>
            <th>Field 5</th>
            <th>Field 6</th>
        </tr>
    </thead>

    <tfoot>
        <tr>
            <th>Field 1</th>
            <th>Field 2</th>
            <th>Field 3</th>
            <th>Field 4</th>
            <th>Field 5</th>
            <th>Field 6</th>
        </tr>
    </tfoot>
</table>

<script type="text/javascript" src="typo3conf/ext/ffs_datatables/Resources/Public/ajaxFunctions.js"></script>

</f:section>

我使用的 js 函数 (ajaxFunctions.js):

var MY_AJAX_ACTION_URL = '<f:uri.action action="list" controller="DatatableController" pageType="5000" />';

$(document).ready(function() {
  $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": {
        type: 'POST',
        url: MY_AJAX_ACTION_URL         
    }
  } );
} );

.. 在我的控制器中:

namespace myVendor\FfsDatatables\Controller;

/**
* DatatableController
*/
class DatatableController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

/**
 * action list
 *
 * @return void
 */
 public function listAction() {

... 我在此处包含以下语法:https://datatables.net/development/server-side/php_mysql 并与 return ...

交换回显
return json_encode( $output );
}
/**
 * action
 *
 * @return void
 */
public function Action() {
}
}

使用的打字稿:

ajaxCall = PAGE
ajaxCall {
  typeNum = 5000
  config {
    disableAllHeaderCode = 1
    additionalHeaders = Content-type:application/json
    xhtml_cleaning = 0
    admPanel = 0
    debug = 0
    no_cache = 1
  }
}

我错过了什么或做错了什么?

我认为您必须在 TypoScript 中添加一行以获取页面的输出:

ajaxCall = PAGE
ajaxCall {
  typeNum = 5000
  config {
    disableAllHeaderCode = 1
    additionalHeaders = Content-type:application/json
    xhtml_cleaning = 0
    admPanel = 0
    debug = 0
    no_cache = 1
  }
  10 < tt_content.list.20.yourextensionname_yourpluginname
}

如果这没有帮助,您不应简单地考虑 return 您的操作中的数据,而是使用自 Extbase 6.2 以来可用的 JsonView。也许这可以给你进一步的帮助: