search

Home  >  Q&A  >  body text

javascript - textStatus error in ajax is reported as parsererror?

The textStatus error in ajax is parsererror.

<!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>

Please give me some advice. I have never encountered this problem before. You can also find other methods. Just wait.

滿天的星座滿天的星座2740 days ago977

reply all(4)I'll reply

  • 黄舟

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

    This probably needs to be combined with the background and specify a parameter named jsonpCallback.

    reply
    0
  • 学习ing

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

    Is the returned thing in jsonp format?

    reply
    0
  • 为情所困

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

    Tips, this is a cross-domain issue. If you wrote the backend, you can configure Cors. The code is as follows. I hope it can help you. By the way, spring needs to be scanned

    /**
     * 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);
        }
    }
    

    reply
    0
  • 天蓬老师

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

    The dataType returned by the background is inconsistent with the dataType requested by ajax

    reply
    0
  • Cancelreply