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. css - 文字排版问题,内容都是动态抓出来的,字数不一定。如何对齐啊2. git - 在web应用分布式部署的情况下怎么进行配置更新3. css3 - 微信前端页面遇到的transition过渡动画的bug4. 网页爬虫 - 关于Python的编码与解码问题5. 前端 - WebStrom安装了angularjs插件,但是没有语法提示6. 微信开放平台 - ios APP能不能打开微信然后通过微信跳转到指定的URL?7. selenium-selenium-webdriver - python 将当前目录加入到 环境变量8. css - input间的间距和文字上下居中9. javascript - imgzoom插件所引发的bug血案!!!!10. php ZipArchive关于不同目录文件压缩

网公网安备