Heim  >  Fragen und Antworten  >  Hauptteil

javascript – TextStatus-Fehler in Ajax wird als Parsererror gemeldet?

Der textStatus-Fehler in Ajax ist 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>

Bitte geben Sie mir einen Rat, ich bin noch nie auf dieses Problem gestoßen. Sie können auch andere Methoden finden, warten Sie einfach ab

滿天的星座滿天的星座2675 Tage vor926

Antworte allen(4)Ich werde antworten

  • 黄舟

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

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

    Antwort
    0
  • 学习ing

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

    返回的东西是jsonp格式吗?

    Antwort
    0
  • 为情所困

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

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

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

    Antwort
    0
  • 天蓬老师

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

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

    Antwort
    0
  • StornierenAntwort