Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应_Ajax_Reactjs_Spring Boot_Microservices - Fatal编程技术网

Ajax 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应

Ajax 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应,ajax,reactjs,spring-boot,microservices,Ajax,Reactjs,Spring Boot,Microservices,从reactjs调用服务到spring boot。低于误差 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应 反应代码: fetch(URL, {method: 'GET', contentType: 'application/json', mode: 'no-cors' }).then (function (response) { return response.json()})

从reactjs调用服务到spring boot。低于误差 跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应

反应代码:

fetch(URL, {method: 'GET',
            contentType: 'application/json',
            mode: 'no-cors'
          }).then (function (response) { return response.json()})
            .then(function (json) {debugger;console.log(json)})
            .catch(function (error) {debugger;console.log(error)});

spring code:

    @GetMapping(path="/user/{aid}", produces= {"application/json"})
    public Optional<User> getUser(@PathVariable int aid) {
        return userRepo.findById(aid);
    }
fetch(URL,{method:'GET',
contentType:'应用程序/json',
模式:“无cors”
}).then(函数(响应){return response.json()})
.then(函数(json){debugger;console.log(json)})
.catch(函数(错误){debugger;console.log(错误)});
弹簧代码:
@GetMapping(path=“/user/{aid}”,products={“application/json”})
公共可选getUser(@PathVariable int-aid){
返回userRepo.findById(aid);
}
错误消息:

跨源读取阻塞(CORB)使用MIME类型application/json阻塞跨源响应


您需要从spring代码应用程序中允许CORS。希望这能有所帮助。

应用程序需要标头,而您正在传递不同的标头, 例如:spring需要应用程序/json头和传递的文本/html

反应代码:

fetch(url, { 
method: 'POST', 
headers: {'Content-Type':'application/json'},
 body: JSON.stringify(data)})

正如在那个url中提到的,我在下面添加了一行,但并没有运气@交叉原点(原点=)