javascript - ajax中的 textStatus 報(bào)錯(cuò)為 parsererror?
問題描述
ajax中的 textStatus 報(bào)錯(cuò)為 parsererror。
<!DOCTYPE html><html> <head><meta charset='UTF-8'><title></title> </head> <body><script src='http://www.lshqa.cn/wenda/js/jquery-1.8.0.min.js' type='text/javascript' charset='utf-8'></script><script src='http://www.lshqa.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),之前真心沒有碰到這種問題,獲取其他方法也可以,坐等
問題解答
回答1:這個(gè)大概要結(jié)合后臺(tái),指明一個(gè)名字為 jsonpCallback 參數(shù)吧。
回答2:返回的東西是jsonp格式嗎?
回答3:題主,這個(gè)是跨域問題如果后端是你寫的話你可以通過配置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. MySQL的聯(lián)合查詢[union]有什么實(shí)際的用處2. mysql時(shí)間格式問題3. mysql 遠(yuǎn)程連接出錯(cuò)10060,我已經(jīng)設(shè)置了任意主機(jī)了。。。4. mysql的主從復(fù)制、讀寫分離,關(guān)于從的問題5. mysql - sql 左連接結(jié)果union右連接結(jié)果,導(dǎo)致重復(fù)性計(jì)算怎么解決?6. php多任務(wù)倒計(jì)時(shí)求助7. 數(shù)組排序,并把排序后的值存入到新數(shù)組中8. 怎么能做出標(biāo)簽切換頁(yè)的效果,(文字內(nèi)容隨動(dòng))9. 默認(rèn)輸出類型為json,如何輸出html10. PHP訂單派單系統(tǒng)
