I am doing an Ajax call from site.com/users/{username}
i wanna access the url site.com/account/deleteComment but when i check in fireBug it is trying to access site.com/users/account/deleteComment
here is my code
$.ajax({
url: "../account/deleteComment/" + deleteID,
success: function () {
$("#comment-" + deleteID).slideUp("fast");
}
});
The url parameter is a string containing the URL you want to reach with the Ajax call, while settings is an object literal containing the configuration for the Ajax request. In its first form, this function performs an Ajax request using the url parameter and the options specified in settings .
You need to specify the url because whenever you make a server request (whether it be using AJAX, or synchronous-old fashion way) you need to tell the browser who to send the request to. Almost all the examples I saw in the jQuery documentation page have a specified URL or some sort (url: "test.
jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!
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.
Change the URL to:
/account/deleteComment/
That way it'll go to the root path:
site.com/account/deleteComment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With