ajax成功功能不适用于数据表 [英] ajax success function not working on datatable

查看:35
本文介绍了ajax成功功能不适用于数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表来显示数据库 mysql 中的列表

I'm using datatable to show list from database mysql

我需要在表加载结束时更新一些输入,然后我使用了成功函数,但这似乎阻止了数据呈现

I need to update some input on end of table loading, then I'm using success function but this seems to prevent data rendering

var table = $('#example').DataTable({
'processing': true,
'serverSide': true,
'ajax': {
  type: 'POST',
  'url': url,
  'data': function (d) {
    console.log(d.order);
    return JSON.stringify( d );
  },

  // EDIT this "my" success function
  success: function( data ) {
    $('#my_input').val(data.return);
  }
}

Json 返回的是:

{
 "data":[[ (datatable value) ]],
 "returned":"myvalue"
}

这里是jsfiddle

here the jsfiddle

编辑http://jsfiddle.net/ntcwust8/95/

推荐答案

你只需要移除成功回调.

You just need to remove success callback.

var table = $('#example').DataTable({
        'processing': true,
        'serverSide': true,
        'ajax': {
          type: 'POST',
          'url': url,
          'data': function (d) {
            console.log(d.order);
            return JSON.stringify( d );
          }
        }

编辑

您需要使用 ajax.dataSrc 属性,它会在 ajax 完成后调用.它也适用于刷新https://datatables.net/reference/option/ajax.dataSrc

you need to use ajax.dataSrc property it will call after ajax finish. It will work on refresh as well https://datatables.net/reference/option/ajax.dataSrc

var table = $('#example').DataTable({
    'ajax': {
      type: 'POST',
      'url': url,
      'data': function (d) {
        console.log(d.order);
        return JSON.stringify( d );
      },
      "dataSrc": function (json) {
       $("#mydata").val(json.recordsTotal);
       return json.data;
        }
    },

  });

这里是更新的小提琴.http://jsfiddle.net/2jkg3kqo/2/

这篇关于ajax成功功能不适用于数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆