Angularjs $http.get以角度给出my index.html的html
这是一个奇怪的问题-事先为所有的代码感到抱歉,但我认为它将帮助您理解我正在尝试的内容。我的index.html中有以下内容Angularjs $http.get以角度给出my index.html的html,angularjs,http,get,Angularjs,Http,Get,这是一个奇怪的问题-事先为所有的代码感到抱歉,但我认为它将帮助您理解我正在尝试的内容。我的index.html中有以下内容 <!DOCTYPE html> <html ng-app="mainApp"><!--Bootstrap the angular application --> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14
<!DOCTYPE html>
<html ng-app="mainApp"><!--Bootstrap the angular application -->
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script><!-- Angular js CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular- route.min.js"></script><!-- This adds support for ngRoute -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-sanitize.min.js"></script><!--This adds support for ngSanitize and bind html-->
<script src="mainapp.js"></script><!-- Main angular application file -->
<script src="scripts/page.js"></script><!--For the Page prototype-->
<link rel="stylesheet" type="text/css" href="mainstyle.css">
<base href="/mainpg/pgBugle/">
<title>[future title]</title>
</head>
<body>
<div ng-view></div><!--This is where our router will place the different fiews-->
</body>
</html>
这在my page.html中-
{{pages.datas}}
<div ng-repeat="page in pages.datas track by $index">
<h3>{{page.pageTitle}}</h3>
<span>{{page.pageAuthor}}</span>
<div>{{page.pageBody}}</div>
</div>
{{pages.datas}
{{page.pageTitle}}
{{page.pageAuthor}}
{{page.pageBody}
这在我的page.json中
[
{
"pageId": 1,
"pageTitle": "A stitch in time",
"pageBody": "<p>This is some</p><p>Content</p>",
"pageAuthor": "James"
},
{
"pageId": 2,
"pageTitle": "Another Time",
"pageBody": "<p>This is a</p><p>lot of information</p>",
"pageAuthor": "Mike"
},
{
"pageId": 3,
"pageTitle": "I like Cheese",
"pageBody": "<p>Cheese is Really</p><p>Good/p>",
"pageAuthor": "Mr. Cheese"
}
]
[
{
“pageId”:1,
“pageTitle”:“时间的一针”,
“pageBody”:“这是一些内容”,
“页面作者”:“詹姆斯”
},
{
“pageId”:2,
“页面标题”:“另一次”,
“pageBody”:“这是大量的信息”,
“页面作者”:“迈克”
},
{
“pageId”:3,
“pageTitle”:“我喜欢奶酪”,
“pageBody”:“奶酪真的很好”,
“页面作者”:“Cheese先生”
}
]
所有文件都位于我编写的路径中,例如page.json位于mainpg/pgBugle目录中名为api的文件夹中。当我运行这个应用程序时,我不会将page.json的内容加载到我的变量中,我在page.js中有$http.get。我得到主页html文件的内容,它显示在我有{{pages.datas}的地方。(我把pages.datas放在那里,试图弄清楚发生了什么,因为我刚得到一个没有错误的空白屏幕。)关于为什么$http会获取index.html而不是我的page.json文件的内容,有什么想法吗?当你请求一个找不到的URL时,有时会返回默认的404内容,这是本例中的index.html页面。这在每个Web服务器上是不同的
首先,确保可以检索“mainpg/pgBugle/api/page.json”,例如,通过浏览器的地址栏转到该URL。服务器是什么样子的?我使用的是本地apache服务器-只是xamppI有一个.htaccess,如果有人在另一条路径上登陆,我会使用它重定向回index.html。这可能是导致它的原因吗?如果将
/mainpg/pgBugle/api/page.json
粘贴到你的浏览器。你看到json了吗?请求和响应的标题是什么?我得到了json文件的内容您是正确的-我禁用了htaccess一分钟,它给出了一个错误,它找不到/mainpg/pgBugle/mainpg/pgBugle/api/page.json,所以它只是给出index.html,因为它不知道还能做什么。所以,我刚刚将我的api调用切换到api/page.json,我们开始运行了!谢谢大家
{{pages.datas}}
<div ng-repeat="page in pages.datas track by $index">
<h3>{{page.pageTitle}}</h3>
<span>{{page.pageAuthor}}</span>
<div>{{page.pageBody}}</div>
</div>
[
{
"pageId": 1,
"pageTitle": "A stitch in time",
"pageBody": "<p>This is some</p><p>Content</p>",
"pageAuthor": "James"
},
{
"pageId": 2,
"pageTitle": "Another Time",
"pageBody": "<p>This is a</p><p>lot of information</p>",
"pageAuthor": "Mike"
},
{
"pageId": 3,
"pageTitle": "I like Cheese",
"pageBody": "<p>Cheese is Really</p><p>Good/p>",
"pageAuthor": "Mr. Cheese"
}
]