Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Simple HTML AngularJS and Intranet server JSON Return?

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Setting up JqueryUI with MVC 5 in Visual Studio 5 22
Html CheckBox obtain Its Value 5 27
Explain this javascript function to me 2 24
Html Newline 7 20
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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)

792 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