javascript - ajax中的 textStatus 報(bào)錯(cuò)為 parsererror?
問(wèn)題描述
ajax中的 textStatus 報(bào)錯(cuò)為 parsererror。
<!DOCTYPE html><html> <head><meta charset='UTF-8'><title></title> </head> <body><script src='http://www.aoyou183.cn/wenda/js/jquery-1.8.0.min.js' type='text/javascript' charset='utf-8'></script><script src='http://www.aoyou183.cn/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>
求大神指點(diǎn),之前真心沒(méi)有碰到這種問(wèn)題,獲取其他方法也可以,坐等
問(wèn)題解答
回答1:這個(gè)大概要結(jié)合后臺(tái),指明一個(gè)名字為 jsonpCallback 參數(shù)吧。
回答2:返回的東西是jsonp格式嗎?
回答3:題主,這個(gè)是跨域問(wèn)題如果后端是你寫的話你可以通過(guò)配置Cors,代碼如下,希望能幫到你,對(duì)了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:
后臺(tái)返回的dataType與ajax請(qǐng)求的dataType不一致
相關(guān)文章:
1. php - 微信開發(fā)驗(yàn)證服務(wù)器有效性2. javascript - 我的站點(diǎn)貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?3. [python2]local variable referenced before assignment問(wèn)題4. javascript - 求幫助 , ATOM不顯示界面!!!!5. Python2中code.co_kwonlyargcount的等效寫法6. python中怎么對(duì)列表以區(qū)間進(jìn)行統(tǒng)計(jì)?7. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?8. javascript - vue+iview upload傳參失敗 跨域問(wèn)題后臺(tái)已經(jīng)解決 仍然報(bào)403,這是怎么回事啊?9. html - 移動(dòng)端radio無(wú)法選中10. mysql - 請(qǐng)問(wèn)數(shù)據(jù)庫(kù)字段為年月日,傳進(jìn)的參數(shù)為月,怎么查詢那個(gè)月所對(duì)應(yīng)的數(shù)據(jù)
