If you only want an alert then why do you write it in a separate file and enqueue it?
You can directly write it inside the invoke_save_post
function using
echo "<script>alert('Api called');</script>";
or if you want to write it in a separate file then you have to write your alert inside the function and call that js function inside the PHP function so it will not execute Until the function is called
for example:
function alert_wrapper(){
alert('Api has been called');
}
Here your alert is called in the front end because there may be a chance this file is loaded in the front end so every time file is loaded your code executes because it will not inside any function.
Related Posts:
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How to do associative array/hashing in JavaScript
- How can I check for “undefined” in JavaScript?
- How to make history.back() without getting a warning on the browser to reload the page?
- Split string into array
- convert Hsl to rgb and hex
- How to play audio?
- How to write a countdown timer in JavaScript?
- TypeScript foreach return [duplicate]
- What does jQuery.fn mean?
- “Uncaught TypeError: Cannot read property ‘style’ of null at.. “
- Difference between document.referrer and window.parent.location.href
- JavaScript replace/regex
- how to render a react component using ReactDOM Render
- What does “javascript:void(0)” mean?
- What does this symbol mean in JavaScript?
- Go back button in a page
- What is the difference between state and props in React?
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- OnChange event using React JS for drop down
- how to get the last character of a string?
- Set timeout for ajax (jQuery)
- Escaping Discord subset of markdown
- ESLint Parsing error: Unexpected token
- Angular ForEach in Angular4/Typescript?
- Timers in React Native (this.setTimeout)
- CSS height 100% percent not working
- How to handle ETIMEDOUT error?
- bootstrap-datetimepicker for bootstrap 4
- Proper way to wait for one function to finish before continuing?
- XMLHttpRequest module not defined/found
- Check if a variable is of function type
- Bootstrap 4 Dropdown Menu not working?
- document.getElementsByClassName().innerHTML always returns “undefined”
- Bower: ENOGIT Git is not installed or not in the PATH
- Converting an object to a string
- JQuery get all elements by class name
- SyntaxError: expected expression, got ‘<'
- Attaching ‘onclick’ event to D3 chart background
- declaration or statement expected javascript/typescript
- The preferred way of creating a new element with jQuery
- How to pass parameters using ui-sref in ui-router to controller
- What does ngf-select do and why is it needed for form validation?
- Is there a way to read standard input with JavaScript?
- How to disable scrolling temporarily?
- JSON.stringify (Javascript) and json.dumps (Python) not equivalent on a list?
- HTML/Javascript change div content
- How do you remove all the options of a select box and then add one option and select it with jQuery?
- Add and remove multiple classes in jQuery
- How To Save Canvas As An Image With canvas.toDataURL()?
- NPM install fails with node-gyp
- What’s the effect of adding ‘return false’ to a click event listener?
- New line in JavaScript alert box
- How do I download a file with Angular2 or greater
- What are alternatives to document.write?
- What are differences between SystemJS and Webpack?
- How to find if div with specific id exists in jQuery?
- TypeError: $ is not a function WordPress
- Fully responsive HTML5 video
- Make Discord bot send picture with message with NodeJS
- RegEx for Javascript to allow only alphanumeric
- How to check for an undefined or null variable in JavaScript?
- HTML anchor link – href and onclick both?
- Remove extra Google Maps script
- Include jQuery UI as a whole
- How to echo JS right after enqueued script to put it into noConflict mode?
- Hooking a callback into the code within a Gutenberg block
- initial open/toggle PluginDocumentSettingPanel panel in document setting block editor gutenberg
- How to add JavaScript code on WordPress properly?
- Disable unneeded scripts in a wordpress installation
- Restrict file types in the uploader of a wp.media frame
- Gutenberg getMedia() in post query doesn’t return all featured images
- Can I change an external script’s HTML?
- How to transform a legacy widget into a block
- const { __ } not working in IE11
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- Cannot use characters ” in jQuery script in WordPress
- How to install cool javascript feature in WordPress?
- How can I load certain JavaScripts only on blog pages?
- jQuery UI Tools (Flowplayer) Issues
- Custom Gutenberg block: access dom element via JavaScript
- Normal for scripts to be loaded after body tag?
- Close modal window after form submit [closed]
- How to display different content on the same page using different URLS
- Change background video when scrolling reaches a certain ID
- Immediate (e.g. without DOMContentLoaded) JS not working
- Client side pre-save Javascript hook on all admin pages
- WP Gutenberg – custom block with two content fields
- Dynamically changing logo on scroll function [closed]
- Script not working in post content
- How to identify which javascript is being executed
- How could I add load more posts to my theme? [closed]
- How to keep close a sub-menu under homepage? [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Contact form 7 hide and show fields depending up on the condition [closed]
- Javascript button to call custom fields data
- Javascript 2 elements dependent onclick .toggle [closed]
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]
- Why is this script not working?
- Astra Mobile Cart Drawer is blank on home page