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?
答案 0 :(得分:3)
$(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
});