Solved

Simple HTML AngularJS and Intranet server JSON Return?

Posted on 2014-04-14
3
696 Views
Last Modified: 2014-04-15
I have a working test service on our local 2012 server which returns JSON like so:

192.168.1.11:8080/api/values

[
  {
    "ID": 1,
    "Name": "sankar",
    "Address": "cuttack",
    "DOB": "1983-01-22T00:00:00"
  },
  {
    "ID": 3,
    "Name": "My Test Name",
    "Address": "My Test Address",
    "DOB": "1980-01-01T00:00:00"
  }
]

Open in new window


I'm using VS2010 and empty asp.net project (one .html page) with the following code to pull a simple list from the local server like so:

<html lang="en" data-ng-app="">    
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
    <script type="text/javascript">

        function ValuesController($scope, $http) {
            $scope.length = 0;
            $scope.data = [];

            $http.get("192.168.1.11:8080/api/values") 
       .then(
           function (result) {
               angular.copy(result.data, $scope.data);
           },
           function () {
               //handle error
           }
       );

        }
    </script>

</head>
<body>

<div data-ng-controller="ValuesController">

    <div class="row">
        <h2>Projects and its Tasks</h2>
        <p>Number of Projects : {{ data.length }}</p>
    </div> 

    <div data-ng-repeat="d in data">

        <p>Name : {{d.Name}}</p>
    </div>

</div>

</body>
</html>

Open in new window

0
Comment
Question by:WorknHardr
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40000138
why : 192.168.1.11:8080/api/values
and not : /api/values
or at least : //192.168.1.11:8080/api/values (if you server listen and host on 192.168.1.11:8080)

Ajax call must use same domain and protocol.
Else it should work fine : http://jsfiddle.net/6Uc5n/
0
 

Author Comment

by:WorknHardr
ID: 40000177
I successfully returned JSON in a browser with or without //. , so I didn't think it mattered. I'll give a try and let you know. Thx
0
 

Author Closing Comment

by:WorknHardr
ID: 40001812
Correct, cross-domain does not work, thx
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question