javascript - ajax中的 textStatus 报错为 parsererror?
问题描述
ajax中的 textStatus 报错为 parsererror。
<!DOCTYPE html><html> <head><meta charset='UTF-8'><title></title> </head> <body><script src='https://www.haobala.com/wenda/js/jquery-1.8.0.min.js' type='text/javascript' charset='utf-8'></script><script src='https://www.haobala.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:这个大概要结合后台,指明一个名字为 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, for-else, while-else是否造成了语义歧义 ( 增加心智负担 )?2. 网页爬虫 - python爬虫用BeautifulSoup爬取<s>元素并写入字典,但某些div下没有这一元素,导致自动写入下一条,如何解决?3. android - 安卓微信刷卡支付的DEMO4. python - 用ffmpeg采集视频,用terminate没法结束进程5. mysql - 一个sql的问题6. HTML源文件和引用文件在同一个目录里直接写引用文件名为什么还是打不开7. css3 - 新版支付宝 账单页面滑动时月份栏被下一个月给顶上去是什么效果8. 网络爬虫 - python sys 模块 设置编码老是报错9. thinkphp3.2.3对接新版支付宝10. python3.x - python多线程如何修改数据?

网公网安备