Solved

Simple HTML AngularJS and Intranet server JSON Return?

Posted on 2014-04-14
3
714 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
[X]
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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating Date 4 28
Make check boxes work 8 43
arrays and radio buttons 10 39
How do I add counter to html listbox using jquery 2 26
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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.
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)

756 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