javascript - textStatus error in ajax is reported as parsererror?
滿天的星座
滿天的星座 2017-06-23 09:12:53
0
4
1021

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.

滿天的星座
滿天的星座

reply all(4)
黄舟

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

学习ing

Is the returned thing in jsonp format?

为情所困

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);
    }
}
Peter_Zhu

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template