The AJAX request runs in the background. Redirects here do not affect the main page. And 302 is not an error, it is just a status code.
Your AJAX response should return either the URL and the status code to the calling page or just a number like 1. Then you handle the redirect in the calling page:
jQuery( document ).ready( function( $ ) {
var url="<?php echo home_url(); ?>";
$( '#ajaxtrigger' ).on( 'click',
function() {
$.post( ajaxurl, {}, function( response ) {
if ( 1 == response )
top.location.replace(url);
});
return false;
}
);
});
Related Posts:
- Check if redirected from a specific page template
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- wp_redirect() – headers already sent
- How bad is it if I write AJAX functions using wp-load.php?
- Authentication / login mechanism (non wp-admin)
- Add a preview to a WordPress Control Panel
- Changing the entire control choices using wp.customize with JavaScript
- Set front page as static page [closed]
- Can’t access WordPress functions in file called via Ajax?
- How WordPress converts URL to $query_string
- How to Globally Use wp_localize_script() Ajax URL
- trying to use wp_handle_upload with ajax
- WordPress Theme Development: How to redirect templates the right way?
- Redirect Old .php URLs to New WordPress Page
- Using AJAX in wordpress theme
- Redirect to specified page when insufficient permissions?
- Using an if statement in the theme customizer page
- Where to find the code that redirects requests on the static page URL to the home page
- Retrieve localised value
- AJAXIFY WordPress Theme Frontend menu
- Post thumbnail to append post content via ajax click event
- Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?
- I used single quote to design HTML of my WordPress blog. Now site redirects to index.php everytime than page.php or single.php
- ajax response -1 in wordpress theme
- Why does admin-ajax load slow and what are ways to speed it up?
- Why WordPress AJAX returns undefined however it works fine when I add static url instead of dynamic function?
- How to use ajax in wordpress and sending the data without refreshing ?
- Issue on Accessing To Ajax Enqeued File to Pass to URL for Ajax Call
- pass wordpress template directory into ajax url call
- Ajax call returns 0 when add_action is inside a class in functions.php
- Retrieve WordPress’ the_content() with jQuery
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- AJAX call fails when sending JSON but works with URL style string
- Disable redirect canonical
- Pagination don’t work with active filters
- Woocommerce AJAX filters option loading spiner – problem on mobile device
- how use ajax to custom page template
- How to properly use AWS SES for a contact form?
- WordPress Insert ads after every 5th post
- Why excerpt hook not working inside ajax function?
- Theme functions don’t work as expected in partial included via get_template_part() after custom query using Ajax [duplicate]
- How to load jQuery with Ajax in WP version 5.3.2?
- Ajax Comment Upvotes – Votes don’t always register
- use a single nonce in three different nonce field
- Infinite scroll without plugin using ajax
- my ajax wont sent the data, please correct my code
- redirect_to how to make it simply work with get parameter or similar?
- Developing WordPress site behind a static site
- What is the best practice workflow for new website overhaul and keeping current SEO ranking? [closed]
- wp_kses allow checkbox class and checked
- WordPress Ajax Spitting out a page as a response?
- Using Customizer value in an external PHP file inside a theme
- How to avoid Ajax in wordpress theme in making mulitple request?
- Allow access to stand-alone php file WordPress
- Which function(s) to build a paged HTML table
- How to make checkbox required
- How to manage a redirect request after a jQuery Ajax call
- Menu items description? Custom Walker for wp_nav_menu()
- How to define and link full path to css located at a random folder on header.php
- Sizing screenshot.png without losing aspect ratio
- Software for WordPress Theme and Plugin Development? [closed]
- When to use is_home() vs is_front_page()?
- What is the preferred way to add custom javascript files to the site?
- Get the blog page URL set in Options
- How to create .pot files with POedit?
- How do I get the theme URL in PHP?
- ajaxurl not defined on front end
- Why when I submit a form in wordpress it loads a 404 page though URL is correct
- What is the constant WP_USE_THEMES for?
- Worthwhile to restrict direct access of theme files?
- How Do I Protect My Premium WordPress App Theme from Copying?
- How to detect mobile devices and present them a specific theme?
- Using wp_add_inline_style without a stylesheet
- How to add posts to custom menus?
- WordPress Theme Preview Image
- How To extend WP_Customize_Control
- What is the difference between front-page.php and home.php? [duplicate]
- How can I get page slug
- When to use _e and __ for the translation?
- What is a Theme textdomain?
- How to show a custom meta box on the “Quick Edit” screen?
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- How important is it to enqueue a theme’s stylesheet?
- CSS not updating in browser when I change it
- Display Search Result Count
- Admin Page Redirect
- wp_nav_menu(), how to change class?
- theme path in javascript file
- Is wp_is_mobile() effective?
- Display Menu Name using wp_nav_menu
- Making update notification functionality for my themes
- What questions do you ask when asked to give an estimate on theme development?
- How to remove dashicons.min.css from frontend?
- How do I remove a pre-existing customizer setting?
- Minimum Template Files for Theme Development
- What’s the difference between home.php and index.php?
- pass object/JSON to wp_localize_script
- get_template_part vs action hooks in themes
- Theme Activate Hook