ewrwr ewrwr - 4 years ago 160
Javascript Question

AngularJs wont link with JSON

For some reason as you can see my Angular Js cant link, here is the site im using. I dont know, is it something wrong with website I dont know. You can check the actual console for problem since i dont understand it. Thanks for helping!

index.html:

<!DOCTYPE html>
<html lang= "en">

<head>
<meta charset="UTF-8" />
<title>Basic Login Form</title>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.8/angular.js" data-semver="1.4.8"></script>
<script src = "https://rawgit.com/nirus/Angular-Route-Injector/master/dist/routeInjector.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular-route.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>

<body ng-app = "app">
<div ng-view>
<div ng-controller = "people">
<ul>
<h2>Names And Ages of Programmers:</h2>
<li ng-repeat = "person in persons">
{{person.Name + ' : ' + person.Age }}
</li>

</ul>
</div>

</div>
</body>
</html>


main.js:

var app = angular.module('app',[])

app.controller('people', function($scope,$http)
$http.get('ftp://checkingprojects.netne.net/public_html/database.json')
.sucess(function(response){
$scope.persons = response.records;
})
})


database.json:

{
"records" : [
{
"Name":"Something",
"Age":"18"
},
{
"Name": "Anonymus",
"Age" : "???"
}


]
}

Answer Source

I'm not sure if you can use HTTP request to access files located on an ftp servers. As I tested your urls, it seems that it's requiring authentication.. so even a simple ajax request using get wouldn't work.

To get the request to work, you'll need to have some sort of authentication. Your server seems to handle basic auth.

so you should have to change your url to:

'ftp://user:pass@checkingprojects.netne.net/public_html/database.json'

If the ftp server support http requests, It should work...Yet, you're breaking the same origin policy. So it won't work unless your ftp server expose some sort of header to Allow Cross Origins.

You should host the json file at the same place as the html files and link it with http.

Looking at your ftp url, I guessed that the right http url should be:

'http://checkingprojects.netne.net/database.json'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download