Ajax訪問controller獲取返回數據

當我們剛搭好框架準備用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層,將返回給瀏覽器一些數據,而這些數據將以何種格式返回?你沒有定義或者設置,該怎麼辦???

解決辦法:
需要在配置文件裏設置數據接收格式如下圖:

這裏寫圖片描述

設置之後頁面可以直接返回結果:
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章