WordPress Custom Table Ajax Receiver

I’m fairly new to using WordPress AND AJAX for that matter. I need to have a Table in my admin area which is populated with enquiries to my site.

I have set up a custom table in the admin panel which is populated by an external database. This works fine. Once this has been populated I want to be able to change a select box to keep track of the status of certain enquiries.

Read More

I have inserted the select boxes and all seems well. At this point however, I want to use AJAX to post the changed state (in particular the index no. of the new selected option) back to my database to be populated.

I have found a number of examples to do with this and have spent a wee while trying to get my head around it but once the AJAX post is sent, I am not sure how OR where to deal with the receipt of this and have it update the database.

At the moment the url which the AJAX post points towards is the .php file in which my custom table is stored.

Could someone please explain what each aspect of the following code does, and what steps I seem to missing:

jQuery(function( $ ) {

$(".select-status").on( 'change', function() {

    var $currentSelect = $(this);
    var currentId = $currentSelect.attr('id');

    var url = "/wp-content/plugins/custom-list-table-example/list-table-example.php"; // the script where you handle the form input.

    console.log(currentId['value']);

    $.ajax({

        type: 'POST',

        url: url,

        data: $currentSelect.serialize(),
        success: function(data) {

            alert(data);

        },
        error: function() {

            alert('There was an error: Failed to update database');

        }

    })

});

});

Where select-status is the class given to each select box.

Any help would be massively appreciated.

This site gave me hope but I can’t see if this is relevant or where I would implement the different parts within WordPress.

Related posts