Magento 2 wrong base url on ajax call on checkout page

Magento 2 wrong base url on ajax call on checkout page

October 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 wrong base url on ajax call on checkout page

Magento 2: Resolving the Mysterious “Undefined” Base URL Issue on Checkout Page

Hello developers,

Today we’re going to dive into an intriguing issue that crops up after upgrading your Magento store to version 2.3.7. The problem lies within the checkout page’s AJAX functionality, where the base URL is being incorrectly generated with an unexpected ‘undefined’ parameter.

The Problem: Incorrect Base URL Generation

Before the upgrade, your AJAX calls looked something like this:

/rest/default/V1/guest-carts/AC72N37Vmo3uGMIXEVQfIDt1ubuZLJws/estimate-shipping-methods

However, post-upgrade, you’re now seeing something horrific:

/checkout/undefined/rest/default/V1/guest-carts/AC72N37Vmo3uGMIXEVQfIDt1ubuZLJws/estimate-shipping-methods

The rogue ‘undefined’ variable has crept into the URL, breaking the whole process.

Investigating the Root Cause

First, let’s rule out some obvious culprits:

  • Base URL Configuration: Double-check your secure and unsecure base URLs in Stores > Configuration > General > Web. Ensure they are correctly set.
  • Module Check: No suspicious third-party modules or customizations seem to be interfering with this process.

The issue seems to originate from the core Magento file located at vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rate-processor/new-address.js.

In the getRates function, we see this piece of code:

storage.post(
    serviceUrl,
    JSON.stringify(payload),
    false
);

The serviceUrl appears to be correctly generated as /rest/default/V1/guest-carts/FsS4QvllSq1vpuxZuC8ycQa0VRMOcQCy/estimate-shipping-methods.

However, upon reaching the .fail() function of your AJAX call, we encounter this monstrosity:

$.ajaxSetup({
    errorPlacement: function(error, element) {
        var $form = $(element).closest('form');
        if (!$form.length) {
            $form = element.parent();
        }

        error.insertAfter(element);
    }
});

The errorPlacement function seems to be the culprit. Somehow, it’s adding an extra parameter to your URL—‘undefined’—before the actual service URL.

Potential Solutions

  1. Revert to a Previous Core File: If you have access to a previous version of this file that didn’t contain this issue, you could revert back to that version. However, this might not always be feasible or sustainable in the long run.

  2. Oversight in Magento Core: It seems like there’s some ambiguity or oversight in the Magento core codebase regarding how URLs are handled during AJAX setup. You may want to open an issue on their GitHub repository: https://github.com/magento/magento2

  3. Custom Patch: If reverting to a previous file version is not an option, you could create a custom patch to override the problematic function in your theme or custom module.

Here’s a basic example of how you might do this:

require(['jquery'], function ($) {
    $.ajaxSetup({
        errorPlacement: function(error, element) {
            var $form = $(element).closest('form');
            if (!$form.length) {
                $form = element.parent();
            }

            // Add your custom logic here to prevent 'undefined' from being added
            error.insertAfter(element);
        }
    });
});

Conclusion

This issue appears to be a bug that has slipped through the cracks in Magento’s core codebase. While no official solution exists yet, reverting to an older version of the file or creating a custom patch seems to be the most viable options.

Remember, always back up your files before making any changes, and test thoroughly on a staging environment before deploying to production.

For more insights into Magento development best practices, feel free to explore our Magento Guides at Laravel Company. We’ll keep you updated if any official solutions or patches are released for this issue.

Happy coding!

Magento 2 Checkout API Extensions

Our network