Solved

Simple HTML AngularJS and Intranet server JSON Return?

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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 the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

744 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

14 Experts available now in Live!

Get 1:1 Help Now