我正在尝试从我的解决方案结构的另一个项目(http://dev.media.....com/app/views/services/..。)加载(dev.project ..... com / app / views / index.html /#eprj / 1)中的html页面使用$ http方法。但是我收到错误:XMLHttpRequest无法加载http://dev.media....com/app/views/services/tabs.html。预检的响应具有无效的HTTP状态代码405.
var mediaUrl = "http://dev.media....com/app/views/services"
var url = mediaUrl + '/tabs.html'
$http({
method: 'GET',
url: url,
headers: {
"Access-Control-Allow-Origin": "*"
}
}).then(function (html) {
// Convert the html to an actual DOM node
var template = angular.element(html.data);
// Append it to the directive element
element.append(template);
return $compile(element.contents())(scope);
});
上面的代码是用AngularJs CustomDirective编写的。
并且在(http://dev.media....com)的web.config中添加了system.webserver标记为
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With, origin, content-type, accept" />
</customHeaders>
</httpProtocol>