加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在Breeze中设置AJAX标头

发布时间:2020-12-16 02:53:14 所属栏目:百科 来源:网络整理
导读:How do I set headers before letting breeze make a request? Example: my service expects a certain key to be part of the request in a header name ‘x-service-key’. Till now,I was using jquery ajax and amplify,so pretty easy to set up the he

How do I set headers before letting breeze make a request?

Example: my service expects a certain key to be part of the request in
a header name ‘x-service-key’. Till now,I was using jquery ajax and
amplify,so pretty easy to set up the header. Since I don’t have any
control over the request that breeze is making,how do I pass extra
stuff like headers?

这个问题是由sujesharukil在我们的IdeaBlade论坛上发布的.我在这里重新提出问题和答案,因为我认为它对Breeze Stack Overflow社区有用.

解决方法

从Breeze 0.70.1开始,我们现在支持完全自定义或替换breeze客户端与服务器上的Web服务之间的任何Ajax通信的能力.

关于我们的Ajax支持的Breeze文档仍在进行中,但希望以下内容可以帮助您入门.

要控制Breeze发出的每个Ajax请求的标头,您可以在应用首次启动时执行以下代码.

var ajaxImpl = breeze.config.getAdapterInstance("ajax");
 ajaxImpl.defaultSettings = {
       headers: { 
           // any CORS or other headers that you want to specify.
           "X-Test-Header": "foo2" 
       },};

或者,您可以拦截单个Ajax调用,并根据请求有选择地添加标头.

var ajaxImpl = breeze.config.getAdapterInstance("ajax");
 ajaxImpl.defaultSettings = {
       beforeSend: function(jqXHR,settings) {
              // examine the jqXHR or settings and customize the headers accordingly.
              jqXHR.setRequestHeader("X-Test-Before-Send-Header","foo2");
       }
 };

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读