I am developing a plugin for a customer and using the Ajax to add new record to the Database. The database table that hold the records has a columns ID i.e. primary key with AUTO_INCREMENT.
For some reason I need to grab the last inserted row's ID from the database and have to attach that ID with another ajax action.
$.ajax({
url: ajaxurl,
data: {
action: 'insert_record',
req_data: formdata
},
success: function(data, textStatus, xhr) {
console.log(data); // Grab last insert id
// use id for another action
},
complete: function(xhr, textStatus) {}
});
I successfully created the record in the relative table but don't know how to get the last inserted record id.