'wp_redirect is only working in Chrome Network, page is not redirecting

I created a custom WordPress Payment Plugin for WooCommerce, Everything is working fine. When I try to use wp_redirect('url'); page starts to load in Browser Network, but the page is not redirecting it gives me the following error:

SyntaxError: Unexpected token < in JSON at position 0



Solution 1:[1]

   if (!wp_doing_ajax()) {
          $url = 'https://www.example.com';
          wp_redirect($url);
        exit;
    }

Wrap your redirect if not doing an ajax request.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mujuonly