Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax URL

Tags:

jquery

ajax

forms

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");
        }
    });
like image 513
Harsha M V Avatar asked Nov 18 '10 10:11

Harsha M V


People also ask

What is URL in jQuery AJAX?

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 .

Does AJAX need a URL?

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.

Can AJAX be used with jQuery?

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!


2 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.

like image 107
Pekka Avatar answered Nov 15 '22 23:11

Pekka


Change the URL to:

/account/deleteComment/

That way it'll go to the root path:

site.com/account/deleteComment
like image 33
Jón Trausti Arason Avatar answered Nov 15 '22 21:11

Jón Trausti Arason