这个错误是由于浏览器的CORS(跨域资源共享)策略导致的。解决这个问题可以在服务器端添加响应头信息,允许跨域访问。

如果你使用的是Java后台,可以在Controller类中添加如下注解:

@CrossOrigin(origins = "*", maxAge = 3600)

其中,origins参数表示允许的跨域地址,*表示任意地址;maxAge表示响应缓存时间,单位为秒。

如果你使用的是其他后台语言,可以参考对应的文档或者搜索相关资料。

示例代码:

$.ajax({
    url: ctx + '/user/register.do',
    type: "POST",
    data: {"nickName": nickName, "email": email, "password1": password1},
    success: function(data) {
        if (data == true) {
            // 模态框
            BootstrapDialog.show({
                title: '',
                closable: false,
                message: '注册成功!',
                buttons: [{
                    label: '确定',
                    action: function(dialog) {
                        // 注册成功,跳转到登录界面
                        window.location.href = ctx + "/static/page/index/login.jsp";
                    }
                }]
            });
        }
    },
    dataType: "json"
});
CORS 跨域请求错误:No 'Access-Control-Allow-Origin' 解决方法

原文地址: https://www.cveoy.top/t/topic/m2BT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录