You shouldn’t do something like this in your JS code:
url: 'https://'+window.location.host+'/admin/admin-ajax.php',
You should use wp_localize_script
and pass proper URL in there.
Let’s say your AJAX call is located in file my-js-file.js
. Somewhere in your theme/plugin you have something like this
wp_enqueue_script( '<SOME_HANDLE>', ... . 'my-js-file.js' , ...);
You should add this after it:
wp_localize_script( '<SOME_HANDLE>', 'MyScriptData', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
And in your JS file it should be
$.ajax({
url: MyScriptData.ajax_url,
type:'post',
Related Posts:
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- How to check if I am in admin-ajax.php?
- gettext does not translate when called in ajax
- Execute one AJAX request after another AJAX request finished
- Ajax and autocomplete
- admin-ajax.php vs Custom Page Template for Ajax Requests
- Load tinyMCE / wp_editor() via AJAX [duplicate]
- Saving (Updating) Post / Page Edits With AJAX
- Is there a hook that fires before an ajax call?
- AJAX request from Chrome Extension to WordPress Website
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Why is admin ajax reloading my page
- Plupload in metabox – AJAX action not working in Class
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- Confused on AJAX submit form through page template
- Ajax call in wordpress not working for subscriber user in front site
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Solve cors problem using rest api or ajax
- WP_Session not acting with AJAX
- Ajaxing in functions.php
- Embedded Twitter feed won’t render nicely when loaded via Ajax
- Help with AJAX front end comment moderation
- Enqueue script in header
- Using ajax with wordpress
- Using foreach inside an ajax function
- wp_ajax_nopriv_xxx is not firing on one site, works on all others. -1 for logged out users
- WP_User_Query ignoring ‘meta_query’ arguments
- Increased CPU load due to admin-ajax.php spam
- Ajax image upload with media_handle_upload and form.js
- Can’t get result from sql using ajax result
- Theme Customizer – Conditional Controls
- Edit a different page in WP Customizer
- Get the_content with ajax
- Caching-Plugins and Ajax-Page-Parts
- Ajax loading duplicate post
- Admin ajax error 400 when passing select value to populate another select
- How do I detect in which page ajax_query_attachments_args is loaded?
- Ajax post returning full html page as response
- AJAX request randomly stop working and returns error 400
- Sending variable from ajax on form submit
- Ajax store response json in variables
- How can I set cookies on both secure and non-secure origins at the same time?
- Variable Products Being Added to Cart with AJAX on Shop and Category Pages
- Audio TAG Not using MediaElement When Page is loaded through ajax
- Is it secure to use admin-ajax.php in front?
- Ajax calls from the theme directory
- How to pass parameters from jQuery ajax into PHP function?
- ajax is returning 0
- How to add ajax url to js using wp_add_inline_script()?
- merge wp rest api query to get posts per category does not work
- WP AJAX post filter > do something with empty value
- How to make a fetch() POST request to wordpress rest api?
- Load more posts in the same category – Ajax + Timber
- How to jQuery Ajax show new data from successful insert?
- Redirect after saving form; and yet use wp_die()
- ajaxt returning object object [closed]
- Load more posts (Ajax) in tabbed sidebar on single.php
- Something strange with ajax
- Why is the file not uploading to the server?
- Get localize of a loaded javascript
- is there’s a way to get the next page content generated by page break block with ajax call?
- Merge PDF files from post custom fields(ACF) into one PDF file and respond back the created PDF file, WordPress(AJAX Request)
- REST public POST giving 403 forbidden nginx
- Query data after an Ajax insert
- How to get next and previous post into ajax formed modal windows?
- Passing value from select form with Ajax not working
- Sending email through Ajax without page refresh hangs on admin_ajax.php
- Is there a public ajax endpoint?
- Why Ajax Doesn’t Work?
- How can i do public ajax call?
- How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)
- Content including hooks inside wp-settings.php are being called twice in WordPress
- Problem when sending file via ajax
- wp_verify_nonce not working on the mobile device
- Frontend AJAX Media Upload returning 404
- Can’t GET Variable from AJAX URL
- 404 error custom post type rest api
- How to update cart total after AJAX success
- Change button text after ajax db update
- How to implement AJAX within a class storing shortcode atts as class variables
- How do I display posts of a specific day?
- (Frontend AJAX) get post data WITH image thumbnail?
- Native WordPress Video Shortcode Not Working After Post is Loaded via Ajax
- Ajax Function call is always returning 0 in front end(without plugin) [closed]
- AJAX Post from same domain to a wordpress page
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Speeding up admin-ajax.php
- admin ajax is not working for non logged in users
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- wp_localize_script not create variable in head section
- AJAX admin Internal 500 error Failed to Upload
- Class property not visible inside ajax callback function?
- 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
- Run PHPMailer function after ajax function completes that adds row to custom table