AJAX in WordPress, sending coords data to MySQL and show after into map

You can’t and shouldn’t directly ping any PHP file inside your theme or plugin folder. It’s not safe, and most importantly, will almost never work since you don’t have access to WordPress’s core.

Instead, create an Admin-Ajax handler and process your code there.

To create one, all you have to do is add these lines to your theme’s functions.php file:

add_action( 'wp_ajax_my_action', 'my_function' );
add_action( 'wp_ajax_nopriv_my_action', 'my_function' );

function my_function(){
    // Your php code here
}

Now, alter your ajax request to ping the admin-ajax.php file:, and include the action in your data:

$.ajax({
    type: 'POST',
    data:  { action : 'my_action', pos : pos},
    url: '/wp-admin/admin-ajax.php'
});

However, I suggest you use wp_localize_script to pass the admin_url() to your Ajax function.

Let’s say you have enqueued your JS file the following way:

add_action( 'wp_enqueue_scripts', 'my_localization_function');
function my_localization_function(){
    // Enqueue your script
    wp_enqueue_script( 'script-handle', 'my-script-url' );
}

You then can localize it. Add this after you enqueue your script:

$translation_array = array(
    'admin_uri' => admin_url('admin-ajax.php') ,
);
wp_localize_script( 'script-handle', 'object_name', $translation_array );

Now, your Ajax call can be this:

$.ajax({
    type: 'POST',
    data:  { action : 'my_action', pos : pos},
    url: object_name.admin_uri
});