0

So I am trying to send Get request with angularjs

However I am getting this error

Error: Argument 'SimpleController' is not a function, got undefined

here is my code

var module = angular.module('myApp', []);

module.config(function ($httpProvider) {
    $httpProvider.defaults.headers.post['SOAPAction'] = 'http://schemas.microsoft.com/sharepoint/soap/UpdateListItems';
});

function SimpleController($scope,$http)
{
    $http({
        url: "http://localhost:8080/petstore/pets/list",
        method: "GET",
    })
    .success(function(data){
        console.log("SUCCESS");
        $scope.pets = data;
    }).error(function() {
        console.log("FAIL");
        console.log("data: "+data+"\nstatus: "+status+"\nheaders: "+headers+"\nconfig: "+config)
        $scope.pets = [ {"id":1,"name":"Angelfish","description":"Saltwater fish from Australia","category":"Fish","imageUrl":"fish1.jpg","price":10}];
    });
}
2
  • Please post <html/> as well, even better a jsfiddle.net Commented May 13, 2013 at 12:44
  • @Abdel-Rahman Shoman, I noticed you've asked 4 questions and have not awarded an answer to anyone. You should be awarding answers by clicking the checkmark next to the one that best answers your question so that future visitors can be helped. Commented May 13, 2013 at 16:33

2 Answers 2

2

Instead of

function SimpleController($scope,$http)...

try using

module.controller('SimpleController',function($scope,$http){

// function body

});

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you have an extra comma causing the invalid function:

$http({
    url: "http://localhost:8080/petstore/pets/list",
    method: "GET",  // <--- remove that comma
})

2 Comments

well yes you are right but it does not make that difference, still not working
If you are getting an undefined error it is because you have some syntax issues. Have you run your code through jslint?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.