javascript - ajax中的 textStatus 報錯為 parsererror?
問題描述
ajax中的 textStatus 報錯為 parsererror。
<!DOCTYPE html><html> <head><meta charset='UTF-8'><title></title> </head> <body><script src='http://m.baoyu77737.com/wenda/js/jquery-1.8.0.min.js' type='text/javascript' charset='utf-8'></script><script src='http://m.baoyu77737.com/wenda/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>
求大神指點,之前真心沒有碰到這種問題,獲取其他方法也可以,坐等
問題解答
回答1:這個大概要結(jié)合后臺,指明一個名字為 jsonpCallback 參數(shù)吧。
回答2:返回的東西是jsonp格式嗎?
回答3:題主,這個是跨域問題如果后端是你寫的話你可以通過配置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); }}回答4:
后臺返回的dataType與ajax請求的dataType不一致
相關(guān)文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. docker - 如何修改運行中容器的配置3. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.4. nignx - docker內(nèi)nginx 80端口被占用5. python3.x - python連oanda的模擬交易api獲取json問題第五問6. javascript - QWebEngineView 如何爬 angular 的動態(tài)數(shù)據(jù)?7. css3 - 沒明白盒子的height隨width的變化這段css是怎樣實現(xiàn)的?8. javascript - webpack熱加載配置不生效9. java - SSH框架中寫分頁時service層中不能注入分頁類10. java - instance method中 static后的<K>是什么意思?
