Yes you should use die();
in ajax function call, but because you’re not returning data and don’t care what is returned it’s not necessary
You should be using nonce, it’s good practice to get used to always using it regardless of the situation.
http://codex.wordpress.org/WordPress_Nonces
http://codex.wordpress.org/AJAX_in_Plugins
You should not be using a function called func
, name it something specific to your setup, ie process_my_lat_lng
To solve the problem of the form being submitted twice, put the ajax call in a function and then call the function on page load:
jQuery(document).ready(function($){
processMyLatLng();
});
function processMyLatLng() {
var lat = 21.458965;
var lng = -11.336985;
jQuery.ajax( ajaxurl, {
type: 'POST',
data: {
'action': 'func',
'lat': lat,
'lng': lng
},
success: function(data) {
// note that i don't want the data to return back to the front-end.
},
error: function(errorThrown) {
console.log(errorThrown);
}
});
}