I am trying to get a response from ajax request in wordpress. But every time I am trying to do the request it gets 0 as the response. Below is my code in java script
$("#submit").click(function(e) {
e.preventDefault();
var ajaxurl = '/WordPress/wp-admin/admin-ajax.php';
alert(dataString);
$.post( ajaxurl,
{
'action': 'my_action',
'data': 'name'
},
function(response){
alert('The server responded: ' + response);
}
);
});
in the function.php
add_action('wp_ajax_my_action','data_insert');
add_action('wp_ajax_nopriv_my_action','data_insert');
function data_insert()
{
echo "hello";
die;
}