1. <tfoot id='5HuLs'></tfoot>
    <legend id='5HuLs'><style id='5HuLs'><dir id='5HuLs'><q id='5HuLs'></q></dir></style></legend>
  2. <small id='5HuLs'></small><noframes id='5HuLs'>

      <bdo id='5HuLs'></bdo><ul id='5HuLs'></ul>
  3. <i id='5HuLs'><tr id='5HuLs'><dt id='5HuLs'><q id='5HuLs'><span id='5HuLs'><b id='5HuLs'><form id='5HuLs'><ins id='5HuLs'></ins><ul id='5HuLs'></ul><sub id='5HuLs'></sub></form><legend id='5HuLs'></legend><bdo id='5HuLs'><pre id='5HuLs'><center id='5HuLs'></center></pre></bdo></b><th id='5HuLs'></th></span></q></dt></tr></i><div id='5HuLs'><tfoot id='5HuLs'></tfoot><dl id='5HuLs'><fieldset id='5HuLs'></fieldset></dl></div>
    1. 随每个骨干网同步请求发送令牌

      Send token with every backbone sync request(随每个骨干网同步请求发送令牌)
        <tfoot id='kjo67'></tfoot>

        <legend id='kjo67'><style id='kjo67'><dir id='kjo67'><q id='kjo67'></q></dir></style></legend>
          <bdo id='kjo67'></bdo><ul id='kjo67'></ul>

          <small id='kjo67'></small><noframes id='kjo67'>

          <i id='kjo67'><tr id='kjo67'><dt id='kjo67'><q id='kjo67'><span id='kjo67'><b id='kjo67'><form id='kjo67'><ins id='kjo67'></ins><ul id='kjo67'></ul><sub id='kjo67'></sub></form><legend id='kjo67'></legend><bdo id='kjo67'><pre id='kjo67'><center id='kjo67'></center></pre></bdo></b><th id='kjo67'></th></span></q></dt></tr></i><div id='kjo67'><tfoot id='kjo67'></tfoot><dl id='kjo67'><fieldset id='kjo67'></fieldset></dl></div>
                  <tbody id='kjo67'></tbody>
              1. 本文介绍了随每个骨干网同步请求发送令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的 PHP api 要求我的前端 Backbone 应用程序的每个请求都提交一个用户令牌,以确保用户...

                My PHP api requires a user token be submitted with every request from my front-end Backbone app to make sure the user...

                1. 处于活动状态
                2. 有权访问资源

                在 Backbone 中进行设置的最简单方法是什么?我猜唯一的方法是覆盖 Backbone.sync,但代码会是什么样子?首选 CoffeeScript.

                What is the easiest way to set this up in Backbone? I am guessing the only way is to overwrite Backbone.sync, but what would the code look like? CoffeeScript preferred.

                还有两件事
                1. 如果我收到 403: Access Forbidden Error
                ,我想将用户重定向到 /login2. 当应用程序启动时,我从 localStorage 中提取包含令牌的用户模型
                3. 我有一个 baseModel 和 baseCollection,所有模型/集合都来自

                Two more things
                1. I would like to redirect the user to /login if I get a 403: Access Forbidden Error
                2. I pull the user model which includes the token from localStorage when the app is bootstrapped
                3. I have a baseModel and baseCollection which all models / collections come from

                推荐答案

                你可以这样做:

                var _sync = Backbone.sync;
                Backbone.sync = function(method, model, options) {
                
                    if( model && (method === 'create' || method === 'update' || method === 'patch') ) {
                        options.contentType = 'application/json';
                        options.data = JSON.stringify(options.attrs || model.toJSON());
                    }
                
                    _.extend( options.data, {
                        "access_token": "some-token"
                    });
                
                    return _sync.call( this, method, model, options );
                }
                

                并且只需监听 fetch/save 方法的失败事件以将用户重定向到 /login

                And just listen for the fail event of fetch/save method to redirect a user to /login

                model.fetch().fail( /* redirect */ )
                

                这篇关于随每个骨干网同步请求发送令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                How to use coffeescript in developing web-sites?(如何在开发网站时使用coffeescript?)
                  <bdo id='xDw3i'></bdo><ul id='xDw3i'></ul>

                      • <small id='xDw3i'></small><noframes id='xDw3i'>

                        <i id='xDw3i'><tr id='xDw3i'><dt id='xDw3i'><q id='xDw3i'><span id='xDw3i'><b id='xDw3i'><form id='xDw3i'><ins id='xDw3i'></ins><ul id='xDw3i'></ul><sub id='xDw3i'></sub></form><legend id='xDw3i'></legend><bdo id='xDw3i'><pre id='xDw3i'><center id='xDw3i'></center></pre></bdo></b><th id='xDw3i'></th></span></q></dt></tr></i><div id='xDw3i'><tfoot id='xDw3i'></tfoot><dl id='xDw3i'><fieldset id='xDw3i'></fieldset></dl></div>
                      • <legend id='xDw3i'><style id='xDw3i'><dir id='xDw3i'><q id='xDw3i'></q></dir></style></legend>
                          <tbody id='xDw3i'></tbody>
                        <tfoot id='xDw3i'></tfoot>