javascript - ajax中的 textStatus 報錯為 parsererror?
問題描述
ajax中的 textStatus 報錯為 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>
求大神指點,之前真心沒有碰到這種問題,獲取其他方法也可以,坐等
問題解答
回答1:這個大概要結合后臺,指明一個名字為 jsonpCallback 參數吧。
回答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. python的文件讀寫問題?2. python - (初學者)代碼運行不起來,求指導,謝謝!3. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat4. window下mysql中文亂碼怎么解決??5. linux - 【已解決】fabric部署的Python項目Apache啟動之后提示403Forbidden該如何解決?6. nginx - pip install python庫報錯7. python - flask sqlalchemy signals 無法觸發8. javascript - js 對中文進行MD5加密和python結果不一樣。9. python - 如何判斷字符串為企業注冊名稱10. 為什么python中實例檢查推薦使用isinstance而不是type?
