3 added 1119 characters in body
source | link

I am developing plugin to called Ajax so I do in the plugin and enqueue js in my main file in js file add action in the data section and that data called another .php file add same action name function add add_action but that after Ajax called gave me error add_action is not defined so please suggest me how to called that Ajax in my plugin.

===js file ==
var ajaxurl = myScript.ajaxurl; (Custom File Ajax URL)
jQuery("#idForm").on('submit', function(){
    var searchIDs = jQuery("#idForm input:checkbox:checked").map(function(){            
        var value = jQuery(this).val();
        var name = jQuery(this).attr('name');
        var rel = jQuery(this).attr('rel');
        var stuff = {'name':name,'value':value,'rel':rel,};
        return stuff;
    }).get();
    var tmp = searchIDs;
        jQuery.ajax({
            type: "POST",
        url: ajaxurl, //Relative or absolute path to response.php file
            data: {
                action     : 'my_ajax_action', // load function hooked to: "wp_ajax_*" action hook
                search_val : JSON.stringify(searchIDs),           // PHP: $_POST['first_name']
                //last_name  : 'Cena',           // PHP: $_POST['last_name']
            },

            //data: {search_val:JSON.stringify(searchIDs)},
            success: function(data){
                alert(data);
            }
        });
});
==========AJax Own File========
add_action( 'wp_ajax_my_ajax_action', 'my_ajax_action_callback' );
function my_ajax_action_callback(){
//Code Here
}

I am developing plugin to called Ajax so I do in the plugin and enqueue js in my main file in js file add action in the data section and that data called another .php file add same action name function add add_action but that after Ajax called gave me error add_action is not defined so please suggest me how to called that Ajax in my plugin.

I am developing plugin to called Ajax so I do in the plugin and enqueue js in my main file in js file add action in the data section and that data called another .php file add same action name function add add_action but that after Ajax called gave me error add_action is not defined so please suggest me how to called that Ajax in my plugin.

===js file ==
var ajaxurl = myScript.ajaxurl; (Custom File Ajax URL)
jQuery("#idForm").on('submit', function(){
    var searchIDs = jQuery("#idForm input:checkbox:checked").map(function(){            
        var value = jQuery(this).val();
        var name = jQuery(this).attr('name');
        var rel = jQuery(this).attr('rel');
        var stuff = {'name':name,'value':value,'rel':rel,};
        return stuff;
    }).get();
    var tmp = searchIDs;
        jQuery.ajax({
            type: "POST",
        url: ajaxurl, //Relative or absolute path to response.php file
            data: {
                action     : 'my_ajax_action', // load function hooked to: "wp_ajax_*" action hook
                search_val : JSON.stringify(searchIDs),           // PHP: $_POST['first_name']
                //last_name  : 'Cena',           // PHP: $_POST['last_name']
            },

            //data: {search_val:JSON.stringify(searchIDs)},
            success: function(data){
                alert(data);
            }
        });
});
==========AJax Own File========
add_action( 'wp_ajax_my_ajax_action', 'my_ajax_action_callback' );
function my_ajax_action_callback(){
//Code Here
}
2 edited tags
| link
1
source | link

Ajax Called in Plugin php file

I am developing plugin to called Ajax so I do in the plugin and enqueue js in my main file in js file add action in the data section and that data called another .php file add same action name function add add_action but that after Ajax called gave me error add_action is not defined so please suggest me how to called that Ajax in my plugin.