AngularJS Directive templateUrl returns 400 though file URL loads

后端 未结 2 1580
栀梦
栀梦 2021-01-18 12:35

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

相关标签:
2条回答
  • 2021-01-18 13:18

    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.

    0 讨论(0)
  • 2021-01-18 13:28

    The IE bug that Chris is referring to is a caching error that allows old content to be re-served when using angular's $http and IE.

    I've written about the subject here: http://benjii.me/2014/07/ie-is-caching-my-angular-requests-to-asp-net-mvc/

    A better fix than removing the bug-fix code is to fix it. Use the following instead:

    //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"] = "Fri, 01 Jan 2010 00:00:00 GMT";
    
    0 讨论(0)
提交回复
热议问题