【发布时间】:2020-01-07 12:40:15
【问题描述】:
我的 html 页面在下面指定的 url 上运行,从我的 html 页面中,我想通过单击按钮来点击我的 rest api 控制器。但是由于没有调用 api 并且主 spring boot 应用程序在 http 端口 8080 上成功启动,因此出现错误。
网址
file:///C:/Users/PF077060/Downloads/project/project/UI%20design/html/Release.html
Ajax 代码:
<script >
$(document).ready(function(){
$("#btn").click(function(event){
event.preventDefault();
alert("AJAX request successfully completed");
ajaxpost();
});
function ajaxpost()
{
console.log("formData1");
var formdata=
{
name:$("#name").val(),
inputcutoff:$("#inputcutoffdate").val(),
releasedate:$("#releaseDate").val(),
status:$("#status").val(),
};
//alert("Changed into json format");
console.log(formdata);
$.ajax({
type : "POST",
contentType : "application/json",
url : "localhost:8080/" + "release/addrelease/",
data : formdata,
success : function(result)
{
alert(result.name);
window.location="Main.html";
},
error : function(e)
{
alert("Error");
console.log("ERROR: ",e);
}
});
resetdata();
}
function resetdata(){
$("#name").val("");
$("#inputcutoffdate").val("");
$("#releaseDate").val("");
$("#status ").val("");
}
});
</script>
错误
CORS 策略已阻止从源“null”访问“localhost:8080/release/addrelease/”处的 XMLHttpRequest:跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https .
任何帮助将不胜感激
【问题讨论】: