shenku
shenku

Reputation: 12468

Setting base url with AngularJs not working

I am using $http.get with a relative url like this:

 $http.get('/api/product')
                .then(function (res) { });

The resultant call is:

GET http://localhost/api/product 404 (Not Found) 

Now the problem is my site is running in IIS under a virtual directory, the structure is like this:

Sites
    - Default Web Site
        - Website (Virtual Directory)
        - Services (Virtual Directory)

So the URL I actually want AngularJs to call is:

GET http://localhost/website/api/product

I have tried setting the BASE element like this:

<base href="Website/">

(And using http://localhost/website/)

But nothing seems to correct the URL?

What can I do? I would still like to use the relative URL with angularjs.

Upvotes: 1

Views: 156

Answers (2)

Steve Lang
Steve Lang

Reputation: 559

Change from

$http.get('/api/product').then(function (res) { });
to
$http.get('/website/api/product').then(function (res) { });

Upvotes: 1

Vlado Pandžić
Vlado Pandžić

Reputation: 5058

Try this: $http.get('api/product') .then(function (res) { });

Upvotes: 1

Related Questions