在Javascript中将数据表的ajax调用从Get转换为Post

时间:2018-02-09 09:26:25

标签: javascript ajax post datatable

我尝试将以下datatable javascript从GET转换为POST方法。代码如下所示,

var pagination = new DatatablesPagination({
    tableSelector: '.casesTable',
    tableContainer: data.tableContainer,
    onError: callbacks.onError,
    iDisplayLength: recordsPerPage,
    pages: 4,
    sAjaxSource: ajaxSource,
    fnServerParams: function(aoData) {
        $.each(additionalQueryParams, function(index, additionalQueryParam) {
            aoData.push(additionalQueryParam);
        });
    },
    fnDrawCallback: function(settings) {
        if (typeof callbacks !== "undefined" && typeof callbacks.onDrawOfAssociatedCases !== "undefined") {
            callbacks.onDrawOfAssociatedCases(settings, reportHolder);
            if ($("#associatedCasesTableWrapper").is(":visible")) {
                updateLocation();
            }
        }
    }
}):

我尝试添加sServerMethod:POST,如下所示,但没有运气。

   sServerMethod: 'POST',
        sAjaxSource : ajaxSource,
        fnServerParams : function ( aoData ) {
            $.each(additionalQueryParams, function(index, additionalQueryParam) {
                aoData.push( additionalQueryParam );
            });
        },

有人可以帮我将此方法从GET转换为POST吗?

1 个答案:

答案 0 :(得分:0)

您的服务/服务器设置可能会使用GET配置,但您正尝试使用来自ajax的POST访问它。尝试将服务设置更改为POST

请参考,

https://datatables.net/forums/discussion/21287/ajax-load-results-in-networkerror-405-method-not-allowed

POST 405 (Method not allowed) when trying to post AJAX request - Laravel 4