WordPress provides a way to access PHP variable into .js file using the wp_localize_script
so if your follow that it’s standard practice (standard practices are always advisable).
Your next question is my-ajax.php and plugin URL. All ajax in WordPress process through admin-ajax.php (Standard one) that file could be found in wp-admin so wp_localize_script
should be like:
wp_localize_script( 'admin-js', 'dtAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));
Now to send data to PHP file with AJAX. Seems your code is ok for JS. I can advise you to use update: instead of stop: however the business logic is up to the requirements.
Also you should remove $(document).ready(function() {
and it’s closing bracket (second last line). it’s not required now.
Here is your code that I’ve updated for your direct reference what I’m saying.
add_action( 'admin_enqueue_scripts',array($this, 'admin_scripts' ));
function admin_scripts() {
wp_register_script( 'admin-js', plugin_dir_url(__FILE__) . '/admin.js', array('jquery'), '', true);
wp_localize_script( 'admin-js', 'dtAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));
wp_enqueue_script( 'admin-js' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_register_style( 'digitable_jquery', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', false, '1.0.0' );
wp_enqueue_style( 'digitable_jquery' );
}
JS file code should look like
jQuery(document).ready(function($){
// $(document).ready(function() {
$('#sortable3, #sortable4').sortable({
connectWith: ".filter-fields-list",
stop: function (event, ui) { // update: instead of stop
var data1 = $('#sortable3').sortable('toArray'); // you can use serialize also instead of toArray
var data2 = $('#sortable4').sortable('toArray'); // you can use serialize also instead of toArray
var sep = "https://wordpress.stackexchange.com/";
var findata = (data1 + sep + data2);
// alert(findata);
$.ajax({
data: findata,
type: 'POST',
url: dtAjax.ajaxurl,
success: function(data) {
alert(("You don't" + dtAjax.ajaxurl));
},
error: function() {
alert(("You suck" + dtAjax.ajaxurl));
},
});
}
}).disableSelection();
// });
});