user6813858 user6813858 - 1 month ago 4
Ajax Question

How to appending url path in jquery

Using

$(this).attr("href");
in jQuery Ajax
url
field gives the URL path but when i use a prefix in front of it like this:

$.ajax({
type: 'GET'
url: 'api/'+ $(this).attr("href");
})


it doesn't work.

Whats going wrong? Is this wrong method or is there a better way?

Answer

$(this) -> will return a wrong result in the object.

Get the value in another place and add the ready result;

var getURL = 'api/'+ $(this).attr("href"); // In the level,where your $(this) is the actual this

$.ajax({
    type: 'GET',
    url: getURL
});