All works fine, when I load page with URL http://localhost/projectName. Ajax URL is http://localhost/projectName/Home/GetDetails
But after loading http://localhost/projectName/Home/Index all my ajax calls are going to http://localhost/projectName/Home/Home/GetDetails and thats wrong.
This looks to me like a Jquery issue but anyhow... you need to use the Url object to generate a relative Url. In the preview this had problems in that it didn't pick up the ajax context, but it does now.
One way would be to put something like this into you script:
var myUrl = '<%= Url.Action("GetDetails","Home"); %>';
$.ajax({
type: "POST",
url: myUrl });
Marked as answer by coosha on Aug 21, 2009 07:59 AM
coosha
Member
2 Points
1 Post
ajax call wrong url
Aug 20, 2009 11:51 AM|LINK
Hi.
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 http://localhost/projectName. Ajax URL is http://localhost/projectName/Home/GetDetails
But after loading http://localhost/projectName/Home/Index all my ajax calls are going to http://localhost/projectName/Home/Home/GetDetails and thats wrong.
Please, how can I solve this?
aspnetmvc url Ajax and MVC
leather
Member
116 Points
27 Posts
Re: ajax call wrong url
Aug 20, 2009 01:29 PM|LINK
This looks to me like a Jquery issue but anyhow... you need to use the Url object to generate a relative Url. In the preview this had problems in that it didn't pick up the ajax context, but it does now.
One way would be to put something like this into you script:
var myUrl = '<%= Url.Action("GetDetails","Home"); %>';
$.ajax({
type: "POST",
url: myUrl });
maverickhyd
Contributor
2718 Points
503 Posts
Re: ajax call wrong url
Aug 20, 2009 06:06 PM|LINK
Hi,
--slash is missing hereYou can Pass URL as
url:"/Home/GetDetails"(with Slash before Home)
or you can send by using url.Action as mentioned in above Post
var urlAction = "<%= Url.Action("GetDetails", "Home") %>";