Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is my first attempt at using Angularjs framework. I am trying to follow this example: http://jsfiddle.net/SAWsA/11/

I am successfully able to get the data in the Json format and it works fine. json data:

[{"Activity_Matrix_ID":"163","Activity_ID":"131","Activity_Date":"2062-02-16","Activity_Category":"Maintanence","Activity_Project":"All Projects","Activity_Description":"Json data ","Activity_Hours":"2"},{"Activity_Matrix_ID":"161","Activity_ID":"129","Activity_Date":"2044-02-25","Activity_Category":"Tech Support","Activity_Project":"All Projects","Activity_Description":"Dummy dummy ","Activity_Hours":""}]

So basically, I want to load the data in $scope.items. I am not sure if it is the good method. I can visit the url and the data looks fine. I am stuck at getting the json correctly from the URL to the angular scope.

I tried following

    <script type="text/javascript">
        var sortingOrder = 'Activity_Projects';
    </script>

<script>
function ctrlRead($scope, $filter) {

         $scope.myData = function(item, event) {

          var responsePromise = $http.get({method: 'GET', url: 'https://url_root_same_domain/timesheet/timesheet_info_table_json.php'}).success(function(data, status, headers, config) {

              $scope.items = data; 
              console.log(data);
            }).
            error(function(data, status, headers, config) {
              alert("No data");
            });
        }
 </script>   
share|improve this question
    
Use Angular's $http.get() to load data. You've provided a lot of code, so it is difficult to sort through. Can you put together a simple sample demonstrating your problem? –  JeffryHouser Feb 19 at 22:12
1  
Hi Jeffry, I am having trouble with $http.get() method. Now the code is edited to show the problematic area. Thanks for the reply. –  deepseas Feb 19 at 22:17

1 Answer 1

Try this:

var responsePromise = $http.get('https://url_root_same_domain/timesheet/timesheet_info_table_json.php').success(...rest of your code here

The $http.get() function's first argument is a URL; not an object; and the method of a get call is already get, so you shouldn't have to do any other changes.

share|improve this answer
    
I am getting this error in the console: "TypeError: Cannot read property 'length' of undefined". I guess the json is still not able to load and it is trying to parse "undefined". –  deepseas Feb 20 at 1:03
    
To,e to pull out a network sniffer then.. –  JeffryHouser Feb 20 at 3:41
    
function PostsCtrlAjax($scope, $http) { $http({method: 'GET', url: 'root_url/timesheet/timesheet_info_table_json.php';}).success(function(da‌​ta) { $scope.items = data; // response data console.log(data); }); } Do you think this syntax is correct? I am pretty sure that I am able to access the json url. I tried putting the php code which retrieves the json data directly into $scope.data and it works fine. –  deepseas Feb 20 at 3:49
    
The syntax looks right to me; however I usually use the helper functions, and don't know the 'native' syntax off the top of my head –  JeffryHouser Feb 20 at 5:30
1  
I was finally able to get the Json data in the console using the URL but it still does not display all the data in the table. I had to inject $http in ctrlRead.$inject = ['$scope', '$filter','$http']; and I had to use JSON.stringify on the returned data.Thanks for the comments and response. I really appreciate it. –  deepseas Feb 20 at 18:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.