My ajax call to the controller works for some pages like http://localhost:2493/anything, and does not work for http://localhost:2493/Account/Login.
this code work for the index page
$(document).ready(function () {
$.ajax({
url: 'Home/GetLinks',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data, function (index, val) {
$('#ListLinks').append('<li><a href="http://'+ val.Url +'" target="_new">' + val.Url + '</a></li>');
});
},
error: function (xhr, status, err) {
console.log('Response code:' + xhr.status);
console.log('[Error:' + err + '] ' + status);
}
});
});
When debug this code on pages like http://localhost:2493/Account/Login I got a error 404.
The JS code is placed in separeted file and its called on the _layout page.
I know the problem is url, so I tried to change the code and use
url: '@Url.Action("Home","GetLinks")',
Then it doesn't work on any page.
How can I write this bit code to work on any page.
Thanks a lot