Unfortunately, wp_enqueue_script doesn’t work that way — the second parameter is for a URL as per the documentation.
But you could use wp_add_inline_script() (if there’s an enqueue’d script to attach it to) or, as in olden times, just hook in to wp_head or wp_footer.
Related Posts:
- Can I use the same nonce for multiple requests on the same page?
- Comparing arrays within a loop
- Real time Duplicate title check
- Load custom field value into div with AJAX
- Accessing a random image via ajax
- Data fetch and delete by ajax request
- Making a follow button, Ajax not talking to php
- Display notification only once
- Ajax form submit within a Post Metabox
- WordPress File handle – fopen, fwrite not working with $.ajax or $.post Jquery
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- doing an ajax request always outputs 0
- Trying to implement Ajax comments in WordPress, getting WP error
- Can’t search posts using WP_QUERY inside AJAX Function
- Woocommerce add to cart quantity buttons with AJAX
- class click counter save number
- Any possible way to make $wpdb->get_results() return anything else than array?
- wordpress count link clicks by ip address
- Ajax – Call to undefined function get_option()
- Ajax load more posts with multiple tax query
- Ajax call not working
- WordPress Sending data to Ajax with select option
- PHP 8, AJAX mail form to function.php doesn’t work
- Ajax random number always the same
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Repeating admin-ajax.php not found error in admin
- populate form fields in a loop with ajax
- How to send Ajax request from my plugin in admin dashboard?
- How to pass Select value from Javascript to PHP to generate select option on change
- AJAX success response is not working but it’s saving my changes
- how to make custom ajax handler?
- Plugins not working on AJAX requests
- How to disable controls in theme customizer?
- How do I Import / Upload Files with jQuery AJAX?
- wp ajax return 0
- WordPress plugin: render only page content using ajax call
- AJAX button action in foreach
- WordPress ajax-action failing because of newline in response
- HTML escaping data with ajax requests
- Ajax button not working
- Function won’t run onclick using Ajax
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- Simple AJAX notification when the new post is added to the database
- Is it possible to create new user from external form using REST API?
- Get related product based on subcategory selected from category id with ID 142
- When echo follow Ajax button inside Ajax pagination template not working?
- jQuery Ajax PHP function call returning [object Object]
- WP_Query with AJAX returning empty array
- Loading Posts & Category with Ajax
- How to get post category list as select in front-end?
- PHP Warning: Missing argument 2
- Is there a hack for using is_page() within the function.php file?
- How to SELECT number from table and use in calculation . Unsupported operand types
- Submit form to db
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How to load previous or next attachment with jquery ?
- Can not call .php files after switching to %postname%
- WordPress Conditional / Multiple Taxonomy Query
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Disclaimer that will show every refresh of the page
- AJAX function running TWICE with WordPress admin-ajax.php
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress Search Ajax + Isotope + InfiniteScroll
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- duplicate posts with ajax load more wordpress
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- Change ajax live search results
- How to call my PHP function with AJAX ? wp_query
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- get_the_author_meta( ‘ID’ ) just return 1
- Update $wpdb query with AJAX
- custom mailchimp form using HTTP API
- $.ajax results in 403 forbidden
- WordPress is setting from header wrongly in wp_mail
- AJAX to add to cart multiple products woocommerce
- WordPress ajax filter returning all posts when it should be filtering by category
- ajaxurl usage for a custom function
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- Prepared DB Query from _POST array
- Pass form attributes to another php template in wordpress
- Custom HTML form using PHP – help with ajax/username validation
- AJAX Returning Way Too Many Posts
- WordPress AJAX load post metadata in modal
- wordpress ajax return 0
- Ajax call URL 404’ing when pushed to staging server
- Modify category archive page loop on functions.php
- Run insert if no entry otherwise run update with ajax
- Adding instant search to wordpress page
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- Load php function with AJAX on modal window
- Cookie not created in AJAX request
- notify users when changed database
- how to display tables via ajax
- Save Edit button then disabled readonly metabox
- getJSON response to PHP
- How to make this shortcode not refresh the whole page when i use it on frontend