zoukankan      html  css  js  c++  java
  • angular ajax

      在使用angular 发送ajax的时候,状态信息是正常的,状态码200,返回的参数是使用@responsebody转换后返回的字串。在前端却总是在调用错误的回调函数,也拿不到正确的反馈信息。

      回调函数中传回的参数是:

      Error: [$http:baddata] http://errors.angularjs.org/1.7.2/$http/baddata?

      在浏览器端调试会出现:

      Error: json.parse: unexpected character at line 1 column 1 of the json data

      这时可能是在springmvc的配置文件中,没有配置json消息转换器,

      

    <!-- Start: 配置json消息转换器 & 参数解析-->
        <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper">
            <property name="dateFormat">
                <bean class="java.text.SimpleDateFormat">
                    <constructor-arg index="0" type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/>
                </bean>
            </property>
        </bean>
        <mvc:annotation-driven>
            <mvc:message-converters register-defaults="true">
                <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>application/json; charset=UTF-8</value>
                        </list>
                    </property>
                    <property name="prettyPrint" value="true"/>
                    <property name="objectMapper" ref="objectMapper"/>
                </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>
        <!-- End: 配置json消息转换器 & 参数解析 -->

      当然也要先导入这些依赖先。

    ---不要装作很努力
  • 相关阅读:
    Linux磁盘文件的命名
    操作系统的基本介绍
    CMOS、BIOS
    CPU的频率、外频、倍频与超频
    学习Linux——计算机概论
    第三季-第14课-有名管道通讯编程
    第三季-第13课-无名管道通讯编程
    第三季-第12课-多进程程序设计
    第三季-第11课-进程控制理论
    第三季-第10课-时间编程
  • 原文地址:https://www.cnblogs.com/goblinn/p/9343079.html
Copyright © 2011-2022 走看看