最近工作中发现,使用angular $http跨域的时候,虽然后台已经配置了跨域允许,但是还是报错。

查资料发现,angular $http 的request的请求头中,默认有:

Access-Control-Request-Headers:x-requested-with  
 
而jQuery/fetch 等其他的ajax请求没有这个默认设置,解决办法有2种。
 
1.在client 端,angular里面设置,例如:
const app = angular.module(config.name)
.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
})

2.或者在server端设置跨域的时候:

res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');

X-Requested-With的更多相关文章

  1. CentOS:ECDSA host key "ip地址" for has changed and you have requested strict checking(转)

    原文地址:http://blog.csdn.net/ausboyue/article/details/52775281 Linux SSH命令错误:ECDSA host key "ip地址& ...

  2. git clone出现的error: The requested URL returned error: 401 Unauthorized

    error: The requested URL returned error: 401 Unauthorized while accessing https://git.oschina.net/.. ...

  3. 共享文件夹:The user has not been granted the requested logon type at this computer

    场景重现 今天做一个项目测试,要用到虚拟机,于是在虚拟机(XP 32)上新建了一个共享的文件夹.然后我在Win7 机器上访问它得到如下的error 消息:

  4. 解决PKIX:unable to find valid certification path to requested target 的问题

    这两天在twitter服务器上忽然遇到这样的异常: e: sun.security.validator.ValidatorException: PKIX path building failed: s ...

  5. ORA-12520: TNS:listener could not find available handler for requested type of server

    当你碰到ORA-12520错误时,如下所示: 英文错误提示: ORA-12520: TNS:listener could not find available handler for requeste ...

  6. com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind

    在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...

  7. asp.net mvc 5 web api 关于Requested resource does not support options 问题

    1.用visual studio 2015 建立一个 web api 应用程序.记住这是一个 web api 应用. 2.新建一个web api . 3.用C#访问,代码如下:[没有问题,返回正确] ...

  8. js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource

    js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...

  9. 解决 java 使用ssl过程中出现"PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"

    今天,封装HttpClient使用ssl时报一下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExc ...

  10. oracle异常:ORA-01422: exact fetch returns more than requested

    ORA-01422: exact fetch returns more than requested 神奇的错误,困扰了我一个下午. 问题描述:明明只有一行记录,结果是报了多条记录的错误.令我百思不得 ...

随机推荐

  1. PAT 列车厢调度   (25分)(栈和容器的简单应用)

    1 ====== <--移动方向 / 3 ===== \ 2 ====== -->移动方向 大家或许在某些数据结构教材上见到过“列车厢调度问题”(当然没见过也不要紧).今天,我们就来实际操 ...

  2. iOS runtime实用篇--和常见崩溃say good-bye

    源码 https://github.com/chenfanfang/AvoidCrash 程序崩溃经历 其实在很早之前就想写这篇文章了,一直拖到现在. 程序崩溃经历1 我们公司做的是股票软件,但集成的 ...

  3. Unity打安卓包 Android 所有错误解决方案大全(几乎囊括所有打包错误 )

    Unity打包出错解决方案 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...

  4. 51Nod 1066:Bash游戏 (巴什博弈)

    1066 Bash游戏  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到 ...

  5. 在 Laravel 5 中使用 Repository 模式实现业务逻辑和数据访问的分离

    1.概述 首先需要声明的是设计模式和使用的框架以及语言是无关的,关键是要理解设计模式背后的原则,这样才能不管你用的是什么技术,都能够在实践中实现相应的设计模式. 按照最初提出者的介绍,Reposito ...

  6. C#中DateTime的缺陷 ---- 代替品DateTimeOffset

    C#中的DateTime在逻辑上有个非常严重的缺陷: > var d = DateTime.Now; > var d2 = d.ToUniversalTime(); > d == d ...

  7. php获取并删除数组的第一个和最后一个元素

    php中如何获取并删除数组的第一个或者最后一个元素?其实这两个过程都可以通过php自带的函数 array_pop 和 array_shift 来完成,下面就具体介绍一下如何来操作.(1)使用 arra ...

  8. JS给HTML5页面<Select></Select>绑定选中项

    获取选中值: function setApprovalPersonName() { var name = $("#approvalPersion").find("opti ...

  9. Android getprop setprop watchprops用法

    转载请注明出处:https://www.cnblogs.com/lialong1st/p/10172973.html 在安卓系统中,当你写了一个脚本,已经添加到开机启动 init.rc 中,即使脚本中 ...

  10. OSI7层封包解包动态图-数据在网络中的传输过程.gif