Based on your comments, I don’t think the MyAjax variable is being localized using wp_localize_script().
In your case, you’ll most likely need something like the following:
wp_localize_script( 'script', 'MyAjax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
That said, I don’t really have enough information to provide a more detailed answer.
EDIT: This and the enqueue scripts call should be inside of the wp_enqueue_scripts
callback:
add_action('wp_enqueue_scripts, 'enqueue_my_scripts' );
function enqueue_my_scripts() {
wp_enqueue_script( 'script', get_template_directory_uri() . '/js/vehicle_parts.js', array ( 'jquery' ), 1.1, true);
wp_localize_script( 'script', 'MyAjax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
}
Related Posts:
- Ajax call always returns 0
- 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
- Use AJAX in shortcode
- wp_get_attachment_image returns different image size
- AJAX handler throws 400 (Bad request) – why?
- ajax live search for post title
- Display random text from a file with the WP built-in AJAX API
- Using email_exists() wp function in an ajax request
- How can I rename the WordPress AJAX URL? [duplicate]
- Most efficient way to get custom database records from 20 buttons and 20 tables?
- Display a function using AJAX
- How do I call wp_mail from HTML?
- Unable to get_the_content(); of a post in WordPress via AJAX
- Ajaxing function in widget class
- Search user metadata with checkboxes via ajax (almost working)
- woocommerce target button with class after ajax update
- Ajax call theme functions from front
- ‘is’ functions and ‘get_query_var’ not working
- Ajax not working properly
- Function call via ajax – can’t figure it out?
- WP Ajax Function Always Returning undefined
- Scripts not appending to element in AJAX call – why?
- Search filter by Post title OR Meta Title Value [duplicate]
- admin-ajax.php + load-scripts.php hanging for minutes
- How to know which ajax file or function is called for action
- How to search using ajax for exact phrase or words in an input field?
- Multisite Ajax serialize return error [object Object]
- Create post using Ajax
- WordPress listen to $_POST in functions.php
- Load Post into DIV with Ajax
- wordpress use single ajax in place of multiple ajax requests in a smarter way
- AJAX error handling for submit function in functions file
- echo custom fields with AJAX
- Dequeue script to prevent javascript event conflict on wordpress child theme
- PHP 7.1 | Warning: A non-numeric value encountered in
- Check if a value exists in database table
- processing form data with ajax
- Email Exists ERROR into Ajax registration form
- How to use get_posts() function in functions.php
- Are innerHTML elements visible to jQuery functions?
- Ajax resetting my global variable
- contact form in template with jquery,validate and ajax
- get content from page through AJAX
- Get URLs for AJAX Filter Checkboxes WordPress
- Message notification for user
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Detect Ajax call inside pre_get_posts function
- Populate Product Regular Price with a calculated ACF Field Value
- Ajax Form Issues using Lightsail (AWS)
- post value to function with Ajax and jQuery
- price of product can’t return when get data of product in functions.php
- WP AJAX Request Not Working
- Ajax in plugin fails – but only on one blog – no idea why
- Using AJAX on frontend: Synchronous XMLHttpRequest deprecation except for admin role
- How to use `foreach()` in ajax call
- i can’t use wordpress functions in ajax loaded php file
- Multiple Notifications SetInterval
- Function stops working
- admin-ajax.php 403 forbidden only when calling from external file
- WordPress Ajaxifying not working properly
- Load scripts into an AJAX div
- Load scripts into an AJAX div
- How to create admin ajax function for my contact form
- admin-ajax.php & my wp-admin folder url showing in header
- same get_posts function works diffrently in tag.php and functions.php
- wordpress ajax is not working for dropdown selection
- Automatic add space if user enters number(any digit)
- functions.php filters not applied in AJAX call
- Pass max posts to Javascript
- Updating site content after an AJAX call without a page reload
- Error function main() is a non-object to construct my Ajax.php
- admin-ajax.php nulls all php variables
- Pass jquery var to a function in functions.php
- Ajax call does not work for this custom code
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Why wp_ajax hooks doesn’t work?
- AJAX values converted to PHP Variables?
- How can I json_encode the output of my function?
- WordPress Custom wp mail template return full template
- iOS and ajaxComplete
- get page_id in ajax to function in functions.php
- How to get variable from other function inside class function using add_action for Ajax call
- Get the ID of the page a menu item links to?
- Add container to nav_menu sub menu
- How to add a rel attribute to images that contains their categories?
- Is it possible to be more page/post specific with admin_enqueue_script?
- Add external js file to footer with id
- Define PHP variable from a seperate API if statement
- Custom Menu in Admin doesn’t change menu in browser
- How can I show different content for different user-levels?
- How to change a meta value (of a published post) after X days.?
- Redirect User Role When on Specific Page
- How to force one script to load before google tag manager script
- I can’t in any way include css in my theme using functions.php
- How to include a hyperlink in the body text of a custom password protected form?
- Get title from IDs in a string
- Update add_image_size
- Function to get the name in database table from the comma separated string
- Way of getting queried loop before the query with a filter hook?
- Why my wp_enqueue_script doesnt work on some page?