Reputation: 1023
I want the path name after i request a url i setting.
let say i put http://www.abc.com
then the server will auto return me to http://www.abc.com/sessionId/folder/default.aspx
and i need to get the return url in jquery.
Got anyway to do this?
i try ajax get/post to get the response header location and it always get null value.
Is a Reference code i show at below
$.ajax({
type: 'POST',
url: '/echo/html',
data: {},
dataType: "json",
success: function(res,status,XHR) {
//var location = XHR..getResponseHeader('Location');
alert(XHR.getResponseHeader('Content-Type'));
alert(XHR.getResponseHeader('Location'));
},
error: function(jqXHR) { }
});
Upvotes: 1
Views: 137
Reputation: 87073
var url = 'http://www.abc.com/sessionId/folder/default.aspx',
cutting = 'http://www.abc.com';
console.log(url.replace(cutting,''));
Also if you wish can follow the solution from @zerkms.
Upvotes: 0
Reputation: 1748
You can use a location object for this:
http://www.w3schools.com/jsref/obj_location.asp
To create one from a url:
var url = document.createElement('a');
url.href = "http://www.abc.com/sessionId/folder/default.aspx";
console.log(url.pathname); // this is what you need.
The link shows a lot more options, from protocol to hash, etc.
Upvotes: 0
Reputation: 254916
var result = 'http://www.abc.com/sessionId/folder/default.aspx',
request = 'http://www.abc.com';
console.log(result.substring(request.length)); // /sessionId/folder/default.aspx
http://jsfiddle.net/zerkms/zNN4D/
Upvotes: 1