0
我打電話API與所有需要的對象返回JSON
(注):如何改變從TXT/HTML,Ubuntu的響應頭的Content-Type,tomcat8
$(document).ready(function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var response = xhr.responseText;
//do stuff with response
}
xhr.open('GET', 'http://mydomain:8080/notes/all', true);
xhr.send(null);
});
HTTP請求:
@RequestMapping(value = {"/all"}, method = RequestMethod.GET, produces = "application/json")
public @ResponseBody List<Note> getAllNotes() {
return noteService.getAllNotes();
}
當我在Mac上本地運行時,一切正常。我的響應頭有Content-Type:application/java,並且Request接受它。
然而,當我上傳我的.war到Ubuntu 16.04
服務器,請求頭的Content-Type變化txt/html
,我也得到
404找不到網頁
。 我在兩臺機器上都使用tomcat8.5.5
。
如何指定/更改請求標頭內容類型?頭
圖片:運行在遠程 和地方
內容類型爲text/html,因爲返回錯誤頁面404,它是一個html頁面並且是有效的內容類型。你需要解決的是爲什麼404在Ubuntu上返回。參考你的Javascript代碼,代碼是否來自同一個應用程序? –