Ajax访问controller获取返回数据

来源:互联网 发布:各国劳动效率数据 编辑:程序博客网 时间:2024/05/22 00:27

当我们刚搭好框架准备用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层,将返回给浏览器一些数据,而这些数据将以何种格式返回?你没有定义或者设置,该怎么办???

解决办法:
需要在配置文件里设置数据接收格式如下图:

这里写图片描述

设置之后页面可以直接返回结果:
这里写图片描述

0 0
原创粉丝点击