JQuery Ajax Url
I Am Doing an Ajax Call from I Wanna Access the Url but When I Check in fireBug It Is Trying to Access Here Is My Code $. Ajax({ Url: "...
I am doing an Ajax call from
i wanna access the url but when i check in fireBug it is trying to access
here is my code
$.ajax({
url: "../account/deleteComment/" + deleteID,
success: function () {
$("#comment-" + deleteID).slideUp("fast");
}
});
5 Answers
Well, then ../../ is going to do the trick, isn't it?
That said, it would probably be a good idea to use absolute URLs here.
url: "/account/deleteComment/" + deleteID,
this will take away your ability to easily move your application into a sub-folder, but in most cases, that is not a problem.
you can use location.origin for get base address
var deleteID;
$.ajax({
url:location.origin + "/account/deleteComment/" + deleteID,
success: function () {
$("#comment-" + deleteID).slideUp("fast");
}
});
<script src=""></script>
$.ajax({
url:location.origin + "/account/deleteComment/" + deleteID,
success: function () {
$("#comment-" + deleteID).slideUp("fast");
}
});
Change the URL to:
/account/deleteComment/
That way it'll go to the root path:
Absolute URL is a good idea in ajax but this is more good and easy way.
Just declared var siteURL = globally.
And used this in every ajax request like below.
<script>
$.ajax({
url: siteURL + '/path/to/file',
type: 'POST',
data: {param1: 'value1'},
});
</script>
Generally, I declared in main index file or config of JS file.
I've just had a similar problem in one of my apps.
The solution I used was
$.url("Config/GetEnvironment")
Which ever directory I am in the URL is rendered correctly.