Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Breeze js-如何在查询响应中处理302重定向_Javascript_Asp.net Mvc_Breeze - Fatal编程技术网

Javascript Breeze js-如何在查询响应中处理302重定向

Javascript Breeze js-如何在查询响应中处理302重定向,javascript,asp.net-mvc,breeze,Javascript,Asp.net Mvc,Breeze,如何处理Breeze查询产生的错误,其中错误是XHR请求获得302重定向响应的结果 这是因为我的控制器受到身份验证的保护,并且当会话过期时,下一个请求被重定向到登录页面-HTTP 302响应将返回登录页面的位置头 当我检查promise返回的error对象时,XHR对象没有使用302代码或任何我可以用来识别错误的东西填充-我假设这是因为严格来说302不是一个错误 我如何使用Breeze捕获这些信息并将浏览器重定向到登录页面,而不知道实际返回给客户端的是什么,这很难回答,但是,您可以通过提供自己的

如何处理Breeze查询产生的错误,其中错误是XHR请求获得302重定向响应的结果

这是因为我的控制器受到身份验证的保护,并且当会话过期时,下一个请求被重定向到登录页面-HTTP 302响应将返回登录页面的位置头

当我检查promise返回的error对象时,XHR对象没有使用302代码或任何我可以用来识别错误的东西填充-我假设这是因为严格来说302不是一个错误


我如何使用Breeze捕获这些信息并将浏览器重定向到登录页面,而不知道实际返回给客户端的是什么,这很难回答,但是,您可以通过提供自己的BreezeAjax适配器来拦截Breeze的ajax响应处理,然后在Breeze看到原始Http响应之前自己处理它。比如:

var origAjaxCtor = breeze.config.getAdapter("ajax");
var newAjaxCtor = function () {
    this.name = "newAjax";
    this._origAjaxCtor = new origAjaxCtor();
}
newAjaxCtor.prototype = new oldAjaxCtor(); // to delegate all other methods
newAjaxCtor.prototype.ajax = function (settings) {
   settings.success = function((data, textStatus, XHR) {
      // interpret the results yourself; augmenting them if needed
      ... { your code here } ...
      // and then call the original success code
      settings.success(data, textStatus, XHR);

   });
   // perform the actual ajax call - this will call your custom success method from    above.
   this._origAjaxCtor.ajax(settings);
}
// register the new adapter
breeze.config.registerAdapter("ajax", newAjaxCtor);
// make this adapter the default
breeze.config.initializeAdapterInstance("ajax", "newAjax", true);