當我們剛搭好框架準備用ajax調用controller層返回json數據時出現如下錯誤:
1.頁面錯誤
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()
2.瀏覽器控制檯錯誤
No 'Access-Control-Allow-Origin' header is present on the requested resource.
原因在於你訪問controller層,將返回給瀏覽器一些數據,而這些數據將以何種格式返回?你沒有定義或者設置,該怎麼辦???
解決辦法:
需要在配置文件裏設置數據接收格式如下圖:
設置之後頁面可以直接返回結果: