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
- Getting failure when using filemtime() with wp_enqueue_style
- How to know if a child theme is being used?
- How to modify an image block in Gutenberg WordPress 5?
- WordPress Settings API error
- How can I get wp_head() as a string instead of echoing it?
- How to access certain WP functions inside custom class, in theme folder
- How can I see what template parts are being called for rendering the viewable page?
- File included into functions.php via require_once() won’t echo?
- Example of a theme organization without all the default wp files in root
- Disable the Custom Internal CSS added by theme.json for Certain Pages
- Unwanted blank lines before tag
- Custom Nav Walker Displaying Values in Sub Menu
- Multisite Redirect issue
- get_query_var() and permalinks
- Set default screen option for appearance -> menus
- Conditional statement to show pagination
- Can I have two different theme for two different language?
- the_permalink() doesn’t work
- WordPress Theme’s 404 File Getting Called Every Page Load?
- How to first edit in local WordPress editor on page and the add code?
- excerpt() shows different result between remote and localhost(development environment)
- Disabling Customizer Selective Refresh shortcut icons for selected controls
- How to create a custom page(not a template) in a theme
- How to override p2 breathe theme plugin in content template file?
- What’s stopping my HTML from rendering in my template parts?
- Default Permalink Type to Postname
- add_filter to parent theme helper class function from child theme
- How to Change custom post type Dashicon Color
- Is there any solution, ide/tool etc., for automatic escaping for WordPress?
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- What $handle does WordPress use for a theme’s implicit style.css?
- Shortcode call not working in WP Template
- help needed for suit designing tool
- How to create nested array attribute
- Redirect to dashboard user once you click on Publish page
- Customizer API Multi Sections in single Panel
- How can i Limit My Wp Theme To Only One Site
- Why https://www. SUBdomain is redirected by WP to https://MAINdomain
- add class to all images inside the content
- Creating a theme just to deploy a single page
- Weird ‘theme update’ error [duplicate]
- How to display only some widgets of a sidebar?
- Custom Infinite-post-scrolling in a custom theme:
- Alternating CSS classes for dynamic content [closed]
- Isotope overlapping .items because of featured images – HELP! [closed]