Title: several admin_enqueue_scripts using the same script
Last modified: March 7, 2021

---

# several admin_enqueue_scripts using the same script

 *  Resolved [vincentavct](https://wordpress.org/support/users/vincentavct/)
 * (@vincentavct)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/several-admin_enqueue_scripts-using-the-same-script/)
 * hello,
    can calling the same script with multiple admin_enqueue_scripts be a 
   problem? I use an autocomplete on a field and a click on a button which saves
   the result in the database. I have a 404 error.
 *     ```
       add_action( 'admin_enqueue_scripts', array( $this, 'add_books_author_js' ) );
       add_action( 'admin_enqueue_scripts', array( $this, 'add_tag_author_js' ) );
       add_action('wp_ajax_nopriv_booticUIAutocomplete', array( $this, 'awp_autocomplete_author' ) );
       add_action('wp_ajax_booticUIAutocomplete', array( $this, 'awp_autocomplete_author' ) );
       add_action('wp_ajax_nopriv_booticUIAddTagAuthor', array( $this, 'awp_add_tag_author' ) );
       add_action('wp_ajax_booticUIAddTagAuthor', 		array( $this, 'awp_add_tag_author' ) );
       ```
   
 *     ```
       public function add_books_author_js() {
       	wp_enqueue_script('books-author-js',get_stylesheet_directory_uri() . '/assets/js/books-author.js',
       array( 'jquery', 'jquery-ui-autocomplete' ),'1.0',false);
       			wp_localize_script(
       				'books-author-js',
       				'BooticUIAutocomplete',
       				[
       					'bootic_author_url' 	=> admin_url('admin-ajax.php'),
       					'bootic_author_nonce' 	=> wp_create_nonce('BooticAuthorNonce'),
       					'pid'					=> $this->pid
       				]
       			);
       			$wp_scripts = wp_scripts();
       			wp_enqueue_style('jquery-ui-css',
       				'//ajax.googleapis.com/ajax/libs/jqueryui/' . $wp_scripts->registered['jquery-ui-autocomplete']->ver . '/themes/smoothness/jquery-ui.css',
       				false, null, false
       			);
       		}
   
       		public function add_tag_author_js() {
       			wp_enqueue_script(
       				'tags-author-js',
       				get_stylesheet_directory_uri() . '/assets/js/books-author.js',
       				array( 'jquery' ),
       				'1.0',
       				false
       			);
       			wp_localize_script(
       				'tags-author-js',
       				'BooticUIAddTagAuthor',
       				[
       					'bootic_add_author_url' 	=> admin_url('admin-ajax.php'),
       					'bootic_add_author_nonce' 	=> wp_create_nonce('BooticAddTagAuthorNonce'),
       					'pid'					=> $this->pid
       				]
       			);
       		}
       ```
   
 * js
 *     ```
       $('.books_author').autocomplete({
       		source: function(request, response) {
       			$.ajax({
       				dataType: 'json',
       				url: BooticUIAutocomplete.bootic_author_url,
   
       				data: {
       					term: request.term,
       					action: 'booticUIAutocomplete',
       					security: BooticUIAutocomplete.bootic_author_nonce,
       				},
   
       				success: function(data) {
       					response($.map(data, function (item) {
       						if(item.list != '')item.list+=', ';
       						return {
       							label: 	item.title,
       							value: 	item.list + item.title + ', ',
       							id: 	item.id,
       							pid:	BooticUIAutocomplete.pid
       						};
       					}));
       				}
       			});
       		},
       		minLength: 3,
       		select: function(event, ui) {
       			console.log(ui.item.label+ ' ' + ui.item.id + ' ' + ui.item.pid);
   
       			var author_id = $('#meta-box-author .inside #list-author-id');
   
       			author_id.val( author_id.val() + ui.item.id + ', ' );
       		},
       	});
   
       	/**
       	 *
       	 * @since 1.0
       	 *
       	 * @return {void}
       	 */
       	$('#books_author_add').click(function(){
       		if( add_author_item() ) $('.books_author').val('');
       		var authors = $('.books_author').val();
       		/*
       		$.ajax({
       			url: BooticUIAddTagAuthor.bootic_add_author_url,
       			type: 'POST',
       			data: {
       				authors: authors,
       				action: 'BooticUIAddTagAuthor',
       				security: BooticUIAddTagAuthor.bootic_add_author_nonce,
       			},
       			success: function(data) {
       				console.log( 'data: ' + data );
       			}
       		});*/
       	});
       ```
   
    -  This topic was modified 5 years, 1 month ago by [vincentavct](https://wordpress.org/support/users/vincentavct/).
    -  This topic was modified 5 years, 1 month ago by [vincentavct](https://wordpress.org/support/users/vincentavct/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [vincentavct](https://wordpress.org/support/users/vincentavct/)
 * (@vincentavct)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/several-admin_enqueue_scripts-using-the-same-script/#post-14146499)
 * i tried registering a second js and calling it for click event. nothing changes.
 *  Thread Starter [vincentavct](https://wordpress.org/support/users/vincentavct/)
 * (@vincentavct)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/several-admin_enqueue_scripts-using-the-same-script/#post-14146624)
 * problem solved, action with Capital letter not reported, sorry

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘several admin_enqueue_scripts using the same script’ is closed to new
replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 1 participant
 * Last reply from: [vincentavct](https://wordpress.org/support/users/vincentavct/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/several-admin_enqueue_scripts-using-the-same-script/#post-14146624)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
