The base url for my project won't work without Home/Index on the end, it returns an ajax error. How can I ensure that if the base url is entered without Home/Index, that it will work without returning an error?
In JavaScript with '/' you can go to the root of the application. So you can use this in mapping your URL for .ajax() method of jQuery. See the below code:
"ajax": {
"url": "/Home/GetTaskLog",
//....
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
In JavaScript with '/' you can go to the root of the application. So you can use this in mapping your URL for .ajax() method of jQuery. See the below code:
The base url for my project won't work without Home/Index on the end, it returns an ajax error. How can I ensure that if the base url is entered without Home/Index, that it will work without returning an error?
Do you mean you delete this line:
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
If so,the compiler does not recognize the URL according to the {controller}/{action}/{id} rules.
id = UrlParameter.Optional can let id could null.
So,../Home/GetTaskLog is not work.
If you must delete default line, you could modify the url in RouteConfig,like:
url: "{controller}/{action}/{id}", //defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
or
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
@bruce: The ajax is used to retrieve data from a database and to populate a dataTable table. In this case GetTaskLog is refering to a function that retrieves data from a database. I can confirm that it works, but only when adding home/index to the end of
the url. I am still getting an ajax error with the above code
@yogyiyogi: Thanks, that still doesn't work though.
@Yuki tao: Thanks for the input but the changes didn't make any difference, I am still getting an ajax error when loading the base url.
but only when adding home/index to the end of the url.
Actually,I can't quite understand this mean.
Is my previous understanding correct?
And what is your ajax error message?
Best Regards
Yuki Tao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
7 Posts
ajax error when loading base url but works when adding home/Index on the end
Feb 04, 2019 04:02 PM|Quektis|LINK
The base url for my project won't work without Home/Index on the end, it returns an ajax error. How can I ensure that if the base url is entered without Home/Index, that it will work without returning an error?
Ajax:
All-Star
57844 Points
15487 Posts
Re: ajax error when loading base url but works when adding home/Index on the end
Feb 04, 2019 05:29 PM|bruce (sqlwork.com)|LINK
your ajax url is incorrect when you don't specify the full url for the hosting page. you should use the url helper:
Participant
1253 Points
926 Posts
Re: ajax error when loading base url but works when adding home/Index on the end
Feb 04, 2019 05:50 PM|yogyogi|LINK
In JavaScript with '/' you can go to the root of the application. So you can use this in mapping your URL for .ajax() method of jQuery. See the below code:
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
All-Star
57844 Points
15487 Posts
Re: ajax error when loading base url but works when adding home/Index on the end
Feb 04, 2019 06:01 PM|bruce (sqlwork.com)|LINK
this requires the site be deployed to the root.
Contributor
3710 Points
1431 Posts
Re: ajax error when loading base url but works when adding home/Index on the end
Feb 05, 2019 07:50 AM|Yuki Tao|LINK
Hi Quektis,
Do you mean you delete this line:
If so,the compiler does not recognize the URL according to the {controller}/{action}/{id} rules.
id = UrlParameter.Optional can let id could null.
So,../Home/GetTaskLog is not work.
If you must delete default line, you could modify the url in RouteConfig,like:
or
More details about route,you could refer to:
https://www.asp.net/mvc/overview/controllers-and-routing
https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/controllers-and-routing/creating-a-route-constraint-cs
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
7 Posts
Re: ajax error when loading base url but works when adding home/Index on the end
Feb 05, 2019 09:11 AM|Quektis|LINK
@bruce: The ajax is used to retrieve data from a database and to populate a dataTable table. In this case GetTaskLog is refering to a function that retrieves data from a database. I can confirm that it works, but only when adding home/index to the end of the url. I am still getting an ajax error with the above code
@yogyiyogi: Thanks, that still doesn't work though.
@Yuki tao: Thanks for the input but the changes didn't make any difference, I am still getting an ajax error when loading the base url.
Contributor
3710 Points
1431 Posts
Re: ajax error when loading base url but works when adding home/Index on the end
Feb 06, 2019 06:15 AM|Yuki Tao|LINK
Hi Quektis,
Actually,I can't quite understand this mean.
Is my previous understanding correct?
And what is your ajax error message?
Best Regards
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.