我不断在控制台上收到 net::ERR_BLOCKED_BY_CLIENT 消息,并在网络选项卡上收到(状态)被阻止的消息

问题描述 投票:0回答:1

我有这段代码,它发出请求从 Laravel 后端获取数组,在我的本地服务器上,它运行顺利,但在我托管它之后,我不断收到 POST 错误“http://127.0.0.1:8000/retrieve net ::ERR_BLOCKED_BY_CLIENT"

$.post("https://vgn.srgasaswsa.com", {
                // Retrieve CSRF token from the meta tag
                _token: document.querySelector(
                    '#registrationForm [name="_token"]'
                ).value,

                // Send the value of the selected item as a parameter
                data: item.value,
            })
                .done((res) => {
                    // Loop it as options in the corresponding Local government <select>
                    $.map(res, (item) => {
                        $(local).append(
                            ` <li class="hover:bg-red-800 hover:text-white hover:font-semibold">
                            <label for="${item}" class="w-full h-fit relative" x-on:click="isFocus = false, message = '${item}'">
                                <input type="radio"
                                            name="${local.substring(1)}"
                                            id="${item}"
                                            value="${item}"
                                            class="absolute top-0 left-0 w-full h-fit opacity-0 cursor-pointer"
                                >
                                <p class="w-full h-fit py-2 text-[50px] lg:text-[1em] lg:text-base font-normal">${item}</p>
                            </label>
                        </li>`
                        );
                    });
                })
                .fail((xhr, status, error) => {
                    console.error(error);
                });```

I changed the POST url affter hosting to the hosting url, but it still showing the same error, 

this is my laravel cors
'paths' => ['api/*', 'sanctum/csrf-cookie'],

'allowed_methods' => ['*'],

'allowed_origins' => ['https://vgn.srgasaswsa.com'],

'allowed_origins_patterns' => [],

'allowed_headers' => ['*'],

'exposed_headers' => [],

'max_age' => 0,

'supports_credentials' => true,
javascript php ajax laravel vite
1个回答
0
投票

嗯......根据您的cors配置,似乎您应该将请求发送到“https://vgn.srgasaswsa.com/retrieve”而不是“http://127.0.0.1:8000/retrieve”。相应地更新 JavaScript 代码中的 URL:

$.post("https://vgn.srgasaswsa.com/retrieve", {
});

不知道是否有帮助

© www.soinside.com 2019 - 2024. All rights reserved.