Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
Angularjs 角度导航提供';错误请求';关于获取模板_Angularjs_Routing_Navigation - Fatal编程技术网

Angularjs 角度导航提供';错误请求';关于获取模板

Angularjs 角度导航提供';错误请求';关于获取模板,angularjs,routing,navigation,Angularjs,Routing,Navigation,我正在尝试将路由添加到我的新应用程序中,这是我第一次使用Angular 我有下面描述的文件或文件片段 app.js 'use strict'; var app = angular.module('myApplication', ['ngResource', 'ngRoute']); app.config(['$httpProvider', function ($httpProvider) { //initialize get if not there if (!$httpP

我正在尝试将路由添加到我的新应用程序中,这是我第一次使用Angular

我有下面描述的文件或文件片段

app.js

'use strict';


var app = angular.module('myApplication', ['ngResource', 'ngRoute']);

app.config(['$httpProvider', function ($httpProvider) {
    //initialize get if not there
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};
    }
    //disable IE ajax request caching
    $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
}]);

// Setting up clientside routes.
app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when(
            '/account/details/:name', {
                templateUrl: 'templates/accountDetails.html',
                controller: 'accountDetailsController'
            })
        .when(
            '/account', {
                templateUrl: 'templates/accountOverview.html',
                controller: 'accountController'
            })
        .when(
            '/temp', {
                templateUrl: 'templates/temp.html',
                controller: 'noneController'
            })
        .otherwise({
            redirectTo: '/account'
        });
}]);
\u Layout.cshtml

<!DOCTYPE html>
<html lang="en" ng-app="myApplication">
<head>
  ....
</head>
<body>
  @RenderBody()
</body>
</html>
@{
    ViewBag.Title = "Index";
}

<div ng-controller="AccountsController">
    <a href="#/account/details/jack">Jack</a>
<div>

<div ng-view />
当我打开应用程序时,我看到由于$routeprovider配置中的“否则”而请求检索预期的“templates/accountOverview.html”。 此请求使用的url有效,我可以在浏览器中打开此url以打开文件。但是当Angular打开文件时,Angular会收到一个“400(错误请求)”

请求和“接受”头之间有一个很大的区别。 浏览器请求:接受:text/html、application/xhtml+xml、application/xml;q=0.9,图像/webp,/;q=0.8 角度请求:接受:application/json,text/plain/

这是怎么回事?为什么Angular要为其模板请求json或纯文本,为什么我的服务器用HTTP_400响应?我怎样才能解决这个问题


我已经搜索了一段时间,但感觉我是唯一一个有这个问题的人:(

显然,下面这行代码是我的问题

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
(此行的来源由另一个问题人触发:)

更好的线路是

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Sat, 01 Jan 2000 00:00:00 GMT';
或者可能

$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

显然下面这行代码是我的问题

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
(此行的来源由另一个问题人触发:)

更好的线路是

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Sat, 01 Jan 2000 00:00:00 GMT';
或者可能

$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

显然下面这行代码是我的问题

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
(此行的来源由另一个问题人触发:)

更好的线路是

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Sat, 01 Jan 2000 00:00:00 GMT';
或者可能

$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

显然下面这行代码是我的问题

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
(此行的来源由另一个问题人触发:)

更好的线路是

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Sat, 01 Jan 2000 00:00:00 GMT';
或者可能

$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

这对我来说也很有用,我在过去5个小时内找到了解决方案。谢谢@Svenlits对我来说也很有用,我在过去5个小时内找到了解决方案。谢谢@Svenlits对我来说也很有用,我在过去5个小时内找到了解决方案。谢谢@Svenl