-2

here is controller code:

   [HttpGet]
    public string test()
    {
        return "hi there";
    }

and here is Angular code:

 function testFunction()
    {
        $http.get('http://localhost:1675/api/Product/test').
            success(function (data, status, headers, config) {

            alert(data);
        }).error(function (data, status, headers, config) {

            alert('Error');

        });
    }

it access the controller but it goes to error function!, when data is checked it was found null! it suppose to return hi there anything wrong in this code?

Saif
  • 2,611
  • 3
  • 17
  • 37
  • Looks like your API does not work correctly. Check it, probably using a REST client or curl. Or have a look at the `data` and `error` values in the `error` callback. Most likely, the issue is not on the Angular side. – qqilihq Mar 25 '17 at 19:42
  • I checked that from browser and it works fine! – Saif Mar 25 '17 at 19:44
  • Have you checked your browser's console log for errors? – qqilihq Mar 25 '17 at 19:53
  • after adding `[Route("Product/test")]` it works, may I know why? – Saif Mar 25 '17 at 20:30
  • not related to the problem (which appears to be a server side route issue), but this is relevant to your code: [Angular HTTP success/error methods deprecated, removed in Angular 1.6](http://stackoverflow.com/questions/35329384/why-are-angular-http-success-error-methods-deprecated-removed-from-v1-6) – Claies Mar 25 '17 at 20:31
  • Above you said, that the URL was working from the browser. It's also unclear what your sever-side technology is. It's very obviously **not** JavaScript. – qqilihq Mar 25 '17 at 20:38

1 Answers1

0

after adding [Route("Product/test")] it works.

    [HttpGet]
    [Route("Product/test")]
    public string test()
    {
        return "hi there";
    }
Saif
  • 2,611
  • 3
  • 17
  • 37