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. docker-machine添加一个已有的docker主机问题2. python - Pycharm的Debug用不了3. java如何高效读写10G以上大文件4. java - 新手求教,当前时间问题?5. apache - nginx 日志删除后 重新建一个文件 就打不了日志了6. html - 用ajax提交表单后,返回验证数据在页面location.href跳转到主页,怎么传递session给主页7. java - tomcat服务经常晚上会挂,求解?8. node.js - node express 中ajax post请求参数接收不到?9. 关于js 字符串 转变成 对应变量10. java - 原生CGLib内部方法互相调用时可以代理,但基于CGLib的Spring AOP却代理失效,为什么?
