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. android - 为 AppBarLayout 设置的背景图片 TransitionDrawable 为什么只在第一次打开的时候有效?2. docker网络端口映射,没有方便点的操作方法么?3. java - 请教一个IO的问题4. nginx - 关于javaweb项目瘦身问题,前期开发后,发现项目占用存贮空间太大,差不多1.2个G,怎么实现瘦身,动态页面主要是jsp。5. mysql - 我的myeclipse一直连显示数据库连接失败,不知道为什么6. node.js - 问个问题 Uncaught (in promise)7. node.js - 安装puer前端服务器不成功8. jquery - 移动端如何写弹性效果9. angular.js - angular内容过长展开收起效果10. java - 一个泛型标签问题

网公网安备