Mostly all wordpress developers write the code to create widgets in admin side. and he use following code:
var ajaxurl ='';
var data = {
action: 'action_function_name'
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert(response);
});
But when he wants to use Ajax at front side without login in Admin side area. then admin-ajax.php file will not run because it is made for only admin. so here I am providing solution:
Just create a new file front-ajax.php and put below code inside the file:
And use front-ajax.php rather than admin-ajax.php in your code. This code is running well at my side.
Leave a Reply