搜索

首页  >  问答  >  正文

javascript - ajax中的 textStatus 报错为 parsererror?

ajax中的 textStatus 报错为 parsererror。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

<code><!DOCTYPE html>

<html>

    <head>

        <meta charset="UTF-8">

        <title></title>

    </head>

    <body>

        <script src="js/jquery-1.8.0.min.js" type="text/javascript" charset="utf-8"></script>

        <script src="js/jq.js" type="text/javascript" charset="utf-8"></script>

        <script type="text/javascript">

            $.ajax({

 

                        type: "GET",

                        url: "http://192.168.20.205:8080/platform/banner/bannerApi",

                        async:true,

                        dataType: "jsonp",  

                        jsonp: "callback",

                        success:function(req){

                            console.log(req);

                    },

                     error:function(XMLHttpRequest, textStatus, errorThrown) {

                          

                       alert(XMLHttpRequest.status);//400

                       alert(XMLHttpRequest.readyState);//2

                       alert(textStatus);//parsererror

                     }

                    });

        </script>

    </body>

</html>

</code>

求大神指点,之前真心没有碰到这种问题,获取其他方法也可以,坐等

滿天的星座滿天的星座2742 天前982

全部回复(4)我来回复

  • 黄舟

    黄舟2017-06-23 09:14:53

    这个大概要结合后台,指明一个名字为 jsonpCallback 参数吧。

    回复
    0
  • 学习ing

    学习ing2017-06-23 09:14:53

    返回的东西是jsonp格式吗?

    回复
    0
  • 为情所困

    为情所困2017-06-23 09:14:53

    题主,这个是跨域问题如果后端是你写的话你可以通过配置Cors,代码如下,希望能帮到你,对了spring要扫描到

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    <code class="java">/**

     * Created by sunny on 2017/6/22.

     */

    public class CorsConfig extends WebMvcConfigurerAdapter {

        @Override

        public void addCorsMappings(CorsRegistry registry) {

            registry.addMapping("/**")

                    .allowedOrigins("*")

                    .allowCredentials(true)

                    .allowedMethods("GET", "POST", "DELETE", "PUT")

                    .maxAge(3600);

     

        }

        @Override

        public void addInterceptors(InterceptorRegistry registry) {

            WebContentInterceptor webContentInterceptor = new WebContentInterceptor();

            CacheControl nocache = CacheControl.noCache();

            webContentInterceptor.addCacheMapping(nocache, "/**");

            registry.addInterceptor(webContentInterceptor);

        }

    }

    </code>

    回复
    0
  • 天蓬老师

    天蓬老师2017-06-23 09:14:53

    后台返回的dataType与ajax请求的dataType不一致

    回复
    0
  • 取消回复