Error in Refreshing Datatable Using AJAX in Codeigniter

Error in Refreshing Datatable Using AJAX in Codeigniter



First sorry for my bad english.
I am trying to create button in my datatable. The button for delete data in that row. Delete function works. The problem is after the delete, my Datatable did not refresh the content (Only when I refresh the page, the content refreshed).



I already try some suggestion in other's stackoverflow.
My datatble id = "data'
var data as global variable.



This is my JavaScript Code (inside document.ready) :


var temp = $('#data').DataTable
(
"columns":
[
null, null, null, null,
null, null, null,
"width": "17%"
]
);

table = JSON.parse('"' + temp + '"');



This is my code for button function


function delete(kode)

var x = confirm("Do you want to delete this data?");

if (x == true)

jQuery.ajax(
type : "POST",
url : "***"
dataType : 'json',
success : function()

table.ajax.reload();
alert("delete success");
,
error : function()

table.ajax.reload();
alert("delete fail");

);



Error in console :



Uncaught Type-error: Cannot read property 'ajax' of undefined
at Object.error (hotel:191)
at u (VM226 jquery.js:2)
at Object.fireWith [as rejectWith] (VM226 jquery.js:2)
at k (VM226 jquery.js:2)
at XMLHttpRequest. (VM226 jquery.js:2)





"Cannot read property 'ajax' of undefined" - Where do you define a variable called table? Your DataTables instance is called temp. You also may not need to reload the whole set of data, just delete that one record from the data. And you probably don't need to reload or modify the table at all in the error callback, since the delete operation failed.
– David
Aug 24 at 9:48



table


temp


error





Table is global variable. my bad, in my post, it should not data = JSON.parse('"' + temp + '"'); but it should be Table = JSON.parse('"' + temp + '"');
– Devin
Aug 25 at 8:37






when i remared the JSON.parse line. It gave me an alert "Invalid JSON response. For more information about this error, please see datatables.net/tn/1"
– Devin
Aug 25 at 8:40





when i remark the JSON.parse line. It gave me an alert "Invalid JSON response. For more information about this error, please see datatables.net/tn/1"; Of course I changed the variable temp to data when I tried it.
– Devin
Aug 25 at 8:49





@David if I may know, why you said the delete opeartion failed? When I checked in my table in database (MySQL) , that row (data) deleted.
– Devin
Aug 25 at 8:53




1 Answer
1



You need to write below in ajax success. It will retrieve or refresh all the data of it.


var $lmTable = $("#data").dataTable(bRetrieve: true);
$lmTable.fnDraw();





TypeError: table.fnDraw is not a function at Object.error (hotel:243) at u (VM140 jquery.js:2) at Object.fireWith [as rejectWith] (VM140 jquery.js:2) at k (VM140 jquery.js:2) at XMLHttpRequest.<anonymous> (VM140 jquery.js:2)
– Devin
Aug 25 at 8:42






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)