when looking with Fidler I see that the page call returns a 404 since it doesn't try to load it to the relative path I'm in (http://localhost/mysite) and it tries to load the root of the server - so the call looks like this http://localhost:80/api/getdetails
when I was writing web forms I used to do ajax calls such as this all the time and it always worked.
what am I missing?
Thanks
I'm writing a small ASP.NET MVC site which also includes a WEB API in it that I wrote.
I've configured the project on my local IIS as http://localhost/mysite
On the main page of my site I'm including a js script that I wrote:
when looking with Fidler I see that the page call returns a 404 since it doesn't try to load it to the relative path I'm in (http://localhost/mysite) and it tries to load the root of the server - so the call looks like this http://localhost:80/api/getdetails
when I was writing web forms I used to do ajax calls such as this all the time and it always worked.
what am I missing?
Thanks
javascript
jquery
ajax
asp-mvc
asp-web-api
Share
Improve this question
edited Feb 2, 2014 at 10:03developer82
asked Feb 2, 2014 at 9:50
developer82developer8213.7k2424 gold badges9393 silver badges163163 bronze badges3
Web API is a REST based system. Try to dig a little deeper into REST and embrace its mindset. Naming the controller "GetDetails" is not restful and it's repetitive too.
– timmkrause
CommentedFeb 2, 2014 at 10:00
@timmkrause thanks - i'll take that into consideration - however, this is not what's causing the problem...
– developer82
CommentedFeb 2, 2014 at 10:03
what output url is @Url.Content("...") like you state in your post, giving? interested in he url pattern...
– deostroll
CommentedFeb 2, 2014 at 10:42
Add a ment
|
2 Answers
2
Reset to default
12
What I ended up doing is in my layout html I've added a js var:
this does the trick no matter how the page looks like. even if I navigate to http://localhost/mysite/home/index
It's probably not the perfect solution, and I definitely think the old webforms way which worked was better - but I guess there are pros and cons to any technology.
Still would be happy to hear if someone has a better solution. for now - this does the trick.
When you navigate to
http://localhost/mysite
The behavior is a little different from
http://localhost/mysite/
Try that to confirm. Without the trailing slash, the "mysite" looks like a document name, not a folder, so relative paths would form from the root of the server.
What you may need to do is pass in the site content URL into your home.js and form absolute paths from it in your code.