javascript - ajax中的 textStatus 報錯為 parsererror?
滿天的星座
滿天的星座 2017-06-23 09:12:53
0
4
884

ajax中的 textStatus 報錯為 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>

求大神指點,之前真心沒有碰到這種問題,取得其他方法也可以,坐等

滿天的星座
滿天的星座

全部回覆(4)
黄舟

這個大概要結合後台,指明一個名字為 jsonpCallback 參數吧。

学习ing

回傳的東西是jsonp格式嗎?

为情所困

題主,這個是跨域問題如果後端是你寫的話你可以透過配置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);
    }
}
Peter_Zhu

後台回傳的dataType與ajax請求的dataType不一致

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!