Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC wrong url in ajax calls

I have wrong URL in my ajax calls.

$.ajax({
    type: "POST",
    url: "Home/GetDetails",
    ......
});

HomeController has action GetDetails().

All works fine, when I load page with URL htp://localhost/projectName Ajax URL is htp://localhost/projectName/Home/GetDetails

But after loading htp://localhost/projectName/Home/Index all my ajax calls are going to htp://localhost/projectName/Home/Home/GetDetails and thats wrong.

Please, how can I solve this?

like image 332
Miro Bartos Avatar asked Aug 20 '09 12:08

Miro Bartos


2 Answers

You should use the Url Helper to generate your URLs...

$.ajax({
    type: "POST",
    url: "<%= Url.Action("GetDetails") %>",
    ......
});
like image 130
Kieron Avatar answered Oct 16 '22 19:10

Kieron


If you stick with the strings and not Url.Action, put a forward slash before 'Home'

url: "/Home/GetDetails"
like image 36
swilliams Avatar answered Oct 16 '22 18:10

swilliams