嘗試從服務器獲取數據的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"></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>
但是,我的控制檯說:對象{消息: 「無頭」,代碼:500}:標題:X- 當我通過這個設置頁眉經過身份驗證,用戶名:15000500000 @ 1 - 這給我的後端開發 添加到代碼headers: { 'X-Authenticated-Userid': '[email protected]' },
我得到錯誤對象{消息: 「錯誤的請求,HTTP代碼:0,錯誤信息:」 代碼:500}
可能是我做錯了什麼?
'500'是內部服務器錯誤。你需要看看你的服務器端錯誤日誌。 – Quentin
您需要啓用CORS –
爲什麼在沒有數據時使用'POST'!使用'GET'代替 –