1

I am using jquery datatable to list my database values. I want create a country and its state in same page while that initially the state datatable is empty.Once I create country the country id is generated and can create state with that country id in same page.It also created fine but the problem is datatable is not reloading it should show the state which was created but its not showing.The problem is country id which is generated is not passing to the ajax parameter in datatable while reloading it.

 country_id=$("#country_id").val();
    dataTable = $('#example').DataTable( {
         "serverSide": true,
    // Load data for the table's content from an Ajax source
        "ajax": {
        "url": datatable_url,
        "type": "POST",
        data:{country_id: $("#country_id").val()},
        error: function () {  // error handling
            $(".table-grid-error").html("");
            $("#table").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
            $("#table-grid_processing").css("display", "none");
        }
    },

    ],
});

I reloading it by

 $.ajax({
    url: 'url',
    type: "POST",
    data: {
     //data
    },
    success: function (data) {
              reload_tabless();
   },

function reload_tabless() {
dataTable.ajax.reload(null, false); //reload datatable ajax
}

Please help me rectify it.

2 Answers 2

1

it looks like you have the url hard coded to the string 'url' in the code that should do the ajax call before calling reload_tabless() which most probably makes the ajax call to fail, thus not executing the success callback.

I don't think you need that extra ajax call. Simply execute reload_tabless instead of that ajax call.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually through that URL i am inserting the state against the country id which is inserted in header in same page ,once the state inserted the datatable should reload and show that newly created state
0

Use "destroy": true inside DataTable section and call DataTable function again.

It will reload DataTable without postback.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.