我有一个在本地主机下运行的API,该API接收POST请求以创建帐户,因此我使用ajax jquery创建了一个简单的“ HTML”页面来调用此API,请参阅:
$.ajax({
type: "POST",
url: "http://localhost:8080/contas/",
data: '{"email":"' + var_email + '"}',
success: function () {
new Noty({text: 'Conta criada com sucesso', theme: 'relax', type: 'info'}).show()
},
dataType: "json"
});
但是我总是
No 'Access-Control-Allow-Origin' header is present on the requested resource.
我的API(春季启动)已经具有@CrossOrigin:
@CrossOrigin(value = "*", origins = "*", maxAge = 3600, allowCredentials = "true", allowedHeaders = "*", methods =
{RequestMethod.GET, RequestMethod.OPTIONS, RequestMethod.POST})
但是我认为如果请求来自同一主机(本地主机)则不需要。