I have a url like
http://www.blah.com/something/maybesomethingelse/Webservices/something.asmx/blah
That is being passed through a jquery ajax request.
I want to remove everything after /Webservices/ so I can stick a new page in for error ha开发者_Python百科ndling.
so ideally this would return
http://www.blah.com/something/maybesomethingelse/Webservices/
Then i could just concat on the new page.
Thanks for your help :)
Simple way: url = url.split(/\/Webservices\/)[0]+"/Webservices/"+yourstuff
or neater
var lastFolder = "/Webservices/";
url = url.split(lastFolder)[0]+lastFolder+yourstuff;
You could use a parser like this one:
http://stevenlevithan.com/demo/parseuri/js/
but in this simple case, you only need to find the last index of "/Webservices/":
var lastIndex = url.lastIndexOf('/Webservices/')
and then take everything from the beginning up to the end of "/Webservices/":
var baseUrl = url.substring(0, lastIndex + 12)
and then append the new page:
var newUrl = baseUrl + '/Error.aspx'
精彩评论