Javascript Ajax post请求
尝试从服务器获取数据Javascript Ajax post请求,javascript,ajax,post,Javascript,Ajax,Post,尝试从服务器获取数据 <html> <header> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></
<html>
<header>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</header>
<body>
<div id="result">Тут будет ответ от сервера</div><br /><br />
<script>
$.ajax({
url: "http://139.196.141.166:8084/course/income/outline",
type: "POST",
data: {},
success:function (data) {//возвращаемый результат от сервера
console.log(data);
},
error: function(xhr, textStatus, error) {
console.log(xhr.statusText);
console.log(textStatus);
console.log(error);
}
});
</script>
</body>
</html>
бббббббббббб
$.ajax({
url:“http://139.196.141.166:8084/course/income/outline",
类型:“POST”,
数据:{},
成功:功能(数据)
控制台日志(数据);
},
错误:函数(xhr、textStatus、error){
console.log(xhr.statusText);
console.log(textStatus);
console.log(错误);
}
});
但是,我的控制台说:Object{message:“no header”,代码:500}
当我通过以下方式设置标题:header:X-Authenticated-Userid:15000500000@1-这是我的后端开发人员
添加到代码标题:{'X-Authenticated-Userid':'15000500000@1“},
我得到错误对象{message:“错误请求,http代码:0,错误消息:”,代码:500}
可能是我做错了什么吗?清空“POST”数据。如果您试图从数据库“获取”数据,建议使用“获取”而不是“发布”
500
是一个内部服务器错误。您需要查看服务器端错误日志。您需要启用CORS。为什么在没有数据的情况下使用POST
!使用GET
instead当我使用GET时,服务器返回的ne方法不允许,我有这个请求{“secure”:{},“extra”:{},“body”:{}}当我使用GET时,服务器返回的ne方法不允许,我有这个请求{“secure”:{},“extra”:{},“body”:{}}JQuery ajax()默认设置为GET,因此无需指定type.type:“POST”-我这样做