AngularJS指令templateUrl返回400虽然文件的URL负载 [英] AngularJS Directive templateUrl returns 400 though file URL loads

查看:146
本文介绍了AngularJS指令templateUrl返回400虽然文件的URL负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC 5页的布局与搜索指令基本指令。我的问题是,templateUrl无法加载(400错误)。如果我直接输入网址到浏览器,我可以毫无困难或错误加载HTML页面。我找不到为什么AJAX调用加载网页失败。

I have a basic directive in a MVC 5 Layout Page with a directive for searching. My problem is that the templateUrl cannot be loaded (400 error). If I enter the URL directly into the browser, I can load the html page without difficulty or error. I cannot find out why the AJAX call to load the page is failing.

Chrome的调试器

Chrome Debugger

这是Chrome的HTML页面加载

app.js

(function() {
     var app = angular.module("mainApp");

     app.directive("basicSearch", function() {
        return {
            templateUrl: 'app/directives/basic-search.html',
            controller: function($scope, search) {
                $scope.keyword = '';
                $scope.exact = false;
                $scope.submitSearch = function () {
                    search.searchByKeyword($scope.keyword, 0, $scope.exact);
                }
            }
        }
     });
}());

基本-search.html

<div>
    <input type="search" ng-model="keyword" name="keyword" />
    <button type="submit" ng-click="submitSearch()"></button>
    <input type="checkbox"ng-model="exact" name="exact" />
    <label for="exact">Exact Match?</label>
</div>

_Layout.cshtml

<html>
     <head>
     <base href="@Request.ApplicationPath" />
     <!--- JS & CS References -->
     <title></title>
     </head>
     <body ng-app="mainApp">
     <!-- Other stuff -->
     <basic-search></basic-search>
     <!-- More other stuff -->
     @RenderBody()
     </body>
</html>

修改
这里是成功的请求(通过浏览器):

EDIT Here is the successful request (via browser):

和这里是失败之一(通过角指令):

and here is the one that fails (via Angular directive):

推荐答案

我解决它。看来有人加入了以下的模块配置为试图解决一个IE漏洞(惊讶,意外):

I solved it. It seems someone added the following to the module config as an attempt to resolve an IE bug (surprise, surprise):

//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";

我删除它,清除了我的缓存和它的正常工作。

I removed it, cleared out my cache and it's working fine.

这篇关于AngularJS指令templateUrl返回400虽然文件的URL负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆