fnReloadAjax(url):两个请求

时间:2014-03-11 08:03:03

标签: datatables jquery-datatables

我想在添加新项目时刷新我的表格。我使用这样的代码:

$("#frm_create_user").submit(function() {

    var formData = getFormData($("#frm_create_user"));

    $.ajax({
        type: "POST",
        url: getApiUrl("/user"),
        dataType: "json",
        contentType: 'application/json',
        data: JSON.stringify({user:{user_ref: formData.user_ref}}),
    }).done(function(r) {

        oTable.fnReloadAjax(getApiUrl("/users?sSearch=" + r.user.userid));

    });

    return false;

});

但出于某种原因,我可以看到两个请求而不是一个。 第一个是正确的 - http://symfony/app_dev.php/api/users?sSearch=kZoh1s23&_=1394204041433

第二个令人困惑 - http://symfony/app_dev.php/api/users?sSearch=kZoh1s23&sEcho=3&iColumns=8&sColumns=&iDisplayStart=0&iDisplayLength=25&mDataProp_0=userid&mDataProp_1=user_ref&mDataProp_2=password&mDataProp_3=vpn_password&mDataProp_4=status_id&mDataProp_5=expire_account&mDataProp_6=created&mDataProp_7=&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch_7=&bRegex_7=false&bSearchable_7=true&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=false&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=true&_=1394204041505

如果删除fnReloadAjax()行,这两个请求就会消失,看起来好像是由fnReloadAjax()

引起的

如何修复它只有http://symfony/app_dev.php/api/users?sSearch=kZoh1s23&_=1394204041433个请求?

1 个答案:

答案 0 :(得分:0)

所有这些令人困惑的参数都是您的服务器端脚本可能需要钳制必须返回到dataTables的数据的信息。 由于我不知道你的服务器端代码,我只能分解他们有用的东西:

&sEcho=3  //No need to react to this, it's just the result of the last ajax call
&iColumns=8 //Your table has 8 columns
&iDisplayStart=0 //You are on page 1
&iDisplayLength=25 //you want to display up to 25 entrys per page
&mDataProp_0=userid //Your first colum gets the value of [userid]
&mDataProp_1=user_ref //Your first colum gets the value of [user_ref]
&mDataProp_2=password //Your first colum gets the value of [password]
etc...
&sSearch=12345&bRegex=true//Your first column is filtered by userid 12345 and this value should be treated as a regex by your datasource
&sSearch_0=&bRegex_0=false//Your second column is not filtered and should not be treated as a regex by your datasource
etc...

&iSortCol_0=0&sSortDir_0=asc //your first column should be sorted ascending
&iSortingCols=1 //you have one column that is sortable
&bSortable_0=true //Column 0 is sortable
&bSortable_1=false //Column 1 is not sortable
etc..

您的服务器端脚本应对这些值做出反应。如果是mysql数据源,则应将其where子句设置为过滤参数,按页面数和每页项数限制,并根据sortinfo进行排序。

如果你想使用数据表的豪华功能,例如分页,排序,单独的列过滤,在处理成千上万的信息时,将ajax返回值钳位以减少服务器负载,则需要这一切。

如果您不需要,只需忽略服务器脚本中的其他参数,只需对您需要的数据做出反应即可。但是留下它们,你可能会在以后需要它们: - )

希望这有帮助

相关问题