Solved

Simple HTML AngularJS and Intranet server JSON Return?

Posted on 2014-04-14
3
690 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now