Request header field sessionId is not allowed by Access-Control-Allow-Headers in preflight response.
2018-03-05 14:23
579 查看
上传图片 跨域请求 出现异常
跨域请求出现异常:Request header field sessionId is not allowed by Access-Control-Allow-Headers in preflight response.原因:调用的接口,请求头中不允许sessionId解决方法:在ajax方法调用之前先把设置的sessionId删除,待处理完成之后,也要记得把sessionId设置回去。删除:
delete jQuery.ajaxSettings.headers['sessionId']
设置回去:
jQuery.ajaxSettings.headers['sessionId'] = Cookies.get("sessionId");
具体案例:
//上传图片功能 function uploadImg(file) { var fd = new FormData(); fd.append('uploadFile', file); //删除请求头中的sessionid delete jQuery.ajaxSettings.headers['sessionId'] $.ajax({ url:uploadUrl, type: "post", // Form数据 dataType:'json', data: fd, cache: false, contentType: false, processData: false, beforeSend:function(xhr){ //删除请求头中的sessionid 这里不一定可以,在本项目中,就不行 // delete jQuery.ajaxSettings.headers['sessionId'] }, success: function (data) { // jQuery.ajaxSettings.headers['sessionId'] = Cookies.get("sessionId"); linkImage = data.visitPath; //上传成功,展示在页面上 展示 linlUrl $("#linkImage").attr("src",linkImage); } }); //将数据设置回去 a27b jQuery.ajaxSettings.headers['sessionId'] = Cookies.get("sessionId"); }
相关文章推荐
- Failed to load http://localhost:8080/team.php: Request header field x-jwt-header is not allowed by Access-Control-Allow-Headers in preflight response.
- 9.如何解决出现AXIOS的Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
- Request header field attachmentdata is not allowed by Access-Control-Allow-Headers in preflight resp
- response错误:Request header field Content-Type is not allowed by Access-Control-Allow-Headers in prefl
- Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight respon
- vue-resource Content-Type is not allowed by Access-Control-Allow-Headers in preflight response
- Request header field Content-Type is not allowed by Access-Control-Allow-Headers
- Request header field Content-Type is not allowed by Access-Control-Allow-Headers跨域
- Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers
- Request header field Content-Type is not allowed by Access-Control-Allow-Headers跨域
- Error :Request header field Content-Type is not allowed by Access-Control-Allow-Headers post请求失败原因
- XMLHttpRequest cannot load – Origin is not allowed by Access-Control-Allow-Origin.
- XMLHttpRequest cannot load – Origin is not allowed by Access-Control-Allow-Origin.
- XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin
- (转)XMLHttpRequest在请求失败(Origin null is not allowed by Access-Control-Allow-Origin.)
- XmlHttpRequesterror:OriginnullisnotallowedbyAccess-Control-Allow-Origin
- XMLHttpRequest cannot load – Origin is not allowed by Access-Control-Allow-Origin.
- XMLHttpRequest在请求失败(Origin null is not allowed by Access-Control-Allow-Origin.)
- jquey XMLHttpRequest cannot load url.Origin null is not allowed by Access-Control-Allow-Origin
- ajax跨域post提交json字符串报错Request header field Content-Type is not allowed by Access-Control-Allow-Header