javascript - ajax中的 textStatus 報錯為 parsererror?
問題描述
ajax中的 textStatus 報錯為 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>
求大神指點,之前真心沒有碰到這種問題,獲取其他方法也可以,坐等
問題解答
回答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不一致
相關文章:
1. 網(wǎng)頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決2. python如何不改動文件的情況下修改文件的 修改日期3. python 正則表達式提取4. 算法 - python 給定一個正整數(shù)a和一個包含任意個正整數(shù)的 列表 b,求所有<=a 的加法組合5. javascript - 微信h5發(fā)送圖文信息,部分設備點擊“發(fā)送”按鈕時沒反應,問題較難重現(xiàn),如何能找到可能存在問題的點?6. javascript - 微信小程序里怎么把頁面轉(zhuǎn)成圖片分享7. 大家好,請問在python腳本中怎么用virtualenv激活指定的環(huán)境?8. python - 求一個在def中可以實現(xiàn)調(diào)用本def滿足特定條件continue效果的方法(標題說不太清楚,請見題內(nèi)描述)9. javascript - JS用ajax爬取百度外賣店家信息10. python - Pycharm調(diào)試代碼進行列表遍歷時,如何直接賦值指定元素
