How to get last inserted id using AJAX?

I know how to get last inserted id with PHP in WordPress by using this:

$wpdb->insert_id;

But is there a way of getting this id on AJAX success and update a hidden field value with it?

Answers


Server Side

    function yourFn(){

        //Your code
        echo $wpdb->insert_id;

    }

Client Side

    $.ajax({url: server_side_url, success: function(result){
            $(Inputfield).val(result);
    }});

Need Your Help

Cannot read PHP structure array in javascript jQuery

javascript php jquery html5

I'm trying to read and show with jQuery a PHP array, explicitly, a parsed SRT subtitle file. I can see all the data together doing console.log(data) after ajax success response, but I want to manip...