Categories
CMS Development Wordpress

ajax_object is not defined when ajax call the funtion

When i call function in php using ajax i get Uncaught (in promise) ReferenceError: ajax_object is not defined

html2canvas(document.getElementById("primary")).then(function(canvas) {
                        console.log("image_base64: ", canvas);


                        var data = {
                            'action': 'bingogames_canvas_save',
                            'play_id': play_id,
                            'image_base64': canvas.toDataURL()
                        };
                        jQuery.post(ajax_object.ajax_url, data, function(response) {
                            console.log('Got this from the server: ', response);
                        });

                    });

My jquery function is in template file an how i supposed to enqueue the template file

add_action( 'init', 'my_script_enqueuer' );
function my_script_enqueuer() {

wp_localize_script( 'add-order-front', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

 wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'add-order-front' );

}

Please help thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *