You just have your arguments lined up wrong. Change the line to
wp_enqueue_script( 'ajax-products', plugins_url( '/js/ajax.js', __FILE__ ), array('jquery'), '1.2', false );
You can use plugins_url()
with the second parameter of __FILE__
to get the directory of the specific pluign, and in the first argument you pass the relative location of your script.
The rest is pretty straight forward – dependencies, version and $in_footer
. As you passed one more arguments, I suppose WordPress thought your version (fifth argument) is true
, as you passed ‘1.2’. But I am not sure about that.
Related Posts:
- Is there a JavaScript API? How to access public and private data in JS?
- Enqueue script dinamically
- wp_localize_script not working on ajax response
- WordPress Ajaxify Problem with Scroll-to [closed]
- Enqueue script in plugin is not working
- wp_enqueue_script() doesn’t work with AJAX
- How to include php-generated javascript?
- 403 error When i send ajax request on WordPress website
- Get localize of a loaded javascript
- I am getting Admin-ajax.php 400 Error
- Ajax is not defined
- why is my main.js not loading?
- Enqueue dynamically generated javascript
- wp_enqueue_media problem
- Ajax navigation and scripts loaded only on certain pages
- wp_localize_script not create variable in head section
- AJAX admin Internal 500 error Failed to Upload
- Refresh HTML Page in Browser Automatically on Timer – Every 15 Min
- How to load wp_editor() through AJAX/jQuery
- How to get a unique nonce for each Ajax request?
- Open a Thickbox with content trough AJAX
- failed to load wp-admin/admin-ajax.php
- Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?
- How to HTML5 FormData Ajax
- Get posts with ajax
- WordPress AJAX Login Screen
- Custom PHP endpoint for a plugin’s AJAX call
- How to link WordPress heartbeat to ajax form
- How can I get logged in user’s session data from admin-ajax?
- When using javascript to dynamically add a textarea, how can I render it as a tinyMCE editor (in wordpress)?
- Drag and drop multiple file upload using Ajax WordPress
- Custom ordering fails after AJAX post filter
- How to securely add an Ajax button to a WP Admin page?
- How to “Load More” posts via AJAX?
- Issue with front-end ajax, getting a 302 redirect when accessing wp-admin/admin-ajax.php
- Prevent page reload after ajax form submission
- WordPress Ajax Getting Response “Null”
- wp_ajax() question.. not using wp_enqueue_script?
- admin-ajax return error 400 for Chrome/Edge but not Firefox
- Using AJAX with Forms
- json encode not work in wordpress
- wordpress and add actions to button by coding
- Get Author Post on author.php with AJAX
- Admin-Ajax Error
- AJAX Call is Only Returning 100 Results from Query
- AJAX and -1 response
- How to make custom button link on the WordPress Admin Bar run by AJAX
- Ways to load admin-ajax faster without initializing all plugins?
- How to make registration form ajax?
- Specify ABSPATH in jQuery url
- Ajax Call 400 Bad Request error with POST request but not with GET request
- While Ajax is working well, media upload isn’t showing the imagines
- How can I call an api before user login
- Problems with wordpress nonces in Ajax call
- Get post content and show it in a div
- Output multi-steps form results in same page
- why does not work ajax that add_action registered in wordpress
- How to get post from pure frontend AJAX (using only post ID)?
- Auto load subcategories content with ajax
- Multiple AJAX requests using the same ajax_object.ajaxurl
- Is there a better way to access transients using javascript
- Filter custom post types by custom field using AJAX
- How to perform a frontend HTTP call with AJAX when plugin save the new settings?
- Refresh loop of custom posts (div) after new post is published
- Use ajax request to load sidebar
- How to change request URL?
- Why the wp_localize_script() does not work correct in my case? ( /wp-admin/admin-ajax.php 400 (Bad Request) )
- Updating failed. The response is not a valid JSON response. specific to my browser when I include javascript in my html
- Automatically refresh div id every 15 seconds with code snippet from .php file
- Should wordpress nonce be placed in html form or in javascript file
- Ajax call returning 0 in page template
- If I leave out the wp_die() in the testiframe function I get the ‘0’ appended to my output. If I put it in, the page w/ iframe linked to it crashes
- how to make sure js is enabled before executing php function
- How to run an ajax call in elementor editor
- 400 Bad Request – Post to admin-ajax.php
- jQuery AJAX url wit variable
- How to pass array from jQuery to PHP with AJAX in WordPress?
- Using existing ajax data that is loaded into page
- How to force the admin-ajax.php file to load over HTTPS?
- Unable to ajax request with meta_query
- get_body_class() in ajax envrionment
- Ajax WordPress pass post URLs
- Should I edit a user meta field with PUT, PATCH, or POST and WP::Editable
- AJAX action returning empty posts array?
- Infinite Scroll
- Cannot add multiple single images at once
- How to send custom variable in Media Uploader ajax request?
- WordPress Ajax JSON success return no being recognized
- WordPress page content only in fancybox except direct click
- Ajax takes 10x as long as it should/could
- How to use AJAX to check if user is still logged-in?
- Closing ajax function file with die() causes error and empty page
- How to load wordpress sidebar using AJAX [duplicate]
- using Ajax: call to undefined function get_option
- How To Pass Ajax Value to PHP Query?
- ajax for visitors wordpress
- PHP cookie not set within AJAX call
- WordPress Ajax send response on every iteration of a loop
- Front-end ajax problem all users and guests getting a 302 redirect when accessing wp-admin/admin-ajax.php
- Use Ajax to get an Options Settings Value