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>
求大神指點,之前真心沒有碰到這種問題,取得其他方法也可以,坐等
为情所困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);
}
}