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 Call pages from a Options Panel
- Gallery thumbnails very small
- Is there a list of all display functions for templates? [closed]
- Featured Image meta box not showing up
- Why does WordPress append numbers to page slugs sometimes? How to reliably style based on page
- WordPress dummy data for theme design
- How to remove ID’s from wp_enqueue_style?
- Custom theme: How to call archive-post.php for viewing blog posts
- Dynamic Post Thumbnail →
- Theme Customizer not displaying saved values in wp_head (CSS)
- Thesis -style Navigation
- How to allow certain PHP functions when using sanitize_callback in the word press customizer
- White screen when attaching css to function.php
- How to allow users to create their own website within my domain? [closed]
- Problem escaping text which contains html markups
- Different text on different sites in a multisite setup
- Editing my theme to try to place the default header at the top of the page breaks the rest of the page content
- WordPress creating images if uploaded image is greater than 960px on one side?
- Create theme for mobile phones and tablets only?
- How to create a WP theme that use BootStrap? [closed]
- Alternatives to handle customizer settings
- Changing sidebar.php and footer.php depending on URL
- Theme Checker Text Domain
- loading javascript after jquery is loaded
- Why does the first page of one category redirect to empty page 4?
- Change default rel attributes for Image Block & Button Block
- ACF get_sub_field ALT TAG in the repeater doesn’t show
- Why front-page.php doesn’t show content of file instead shows loop
- How to Detect “Your homepage displays” setting in wordpress
- Why does wp_customizer default values do not apply when theme is installed for the first time?
- How Do I Create a WordPress Demo Site with Limited Admin Access
- Are paginated comments required for publishing Themes?
- Custom theme vs theme customization?
- Data not saved WordPress Custom Admin Page
- Usage of wp_send_json_success and wp_redirect at the same time
- “No Data Received” error in Chrome every time i try to update the theme functions file
- Default calendar widget not showing up
- Can’t attach Javascript to theme
- 404 on child page template
- get_header() on new page fatal error
- Configuring static page with add_rewrite_rule gives 404 after navigating to Permalinks admin panel
- custom wordpress theme blog page always not showing the last two pages of the articles
- Cart button not working on mobile version [closed]
- Homepage with latest posts does not include current-menu-item
- WordPress 6.4.2 – can’t load editor style css using ‘after_setup_theme’ or ‘admin_init’ actions