[英]Get last folder name from URL path , getJSON Api , in javascript
[英]Update last path on the URL with javascript
我使用分頁進行過濾系統,嘗試根據當前URL使用Javascript重定向時遇到麻煩。
我可以使用此類URL,其中最后一個數字是過濾器:
http://localhost/posts/yourPosts/1
http://localhost/posts/subscriptions/3
在每種類型的內部,第2頁將以這種方式顯示:
http://localhost/posts/yourPosts/1/page:2?url=posts%2FyourPosts
http://localhost/posts/subscriptions/3/page:2?url=posts%2FSubscriptions
我目前正在使用:
window.location.href = currentURL + '/' + encodeURI($(this).val());
$(this).val是要使用的過濾器的編號。
問題是,當我使用此URL時,它運行良好:
http://localhost/posts/yourPosts/
http://localhost/posts/subscriptions/
但是,當我在第二頁時,我想顯示過濾器編號3(可以說是汽車而不是動物),但不是。 它顯示如下:
http://localhost/posts/subscriptions/2/page:2?url=posts%2FyourPosts/3
代替這個:
http://localhost/posts/subscriptions/3
有沒有簡單的方法可以處理URL來解決此類問題?
我不能使用絕對路徑,因為URL並不完全相同。 那么...有什么辦法可以更改URL的最后一個PATH?
快速且有點臟:
function fixmybadfilterurl(mybadurl)
{
var parts = mybadurl.split('?');
var subpart2 = parts[parts.length-1].split('/');
var subpart1 = parts[0].split('/');
subpart1.pop();
subpart1.pop();
return(subpart1.join('/')+'/'+subpart2[subpart2.length-1]);
}
所以
fixmybadfilterurl('http://localhost/posts/subscriptions/2/page:2?url=posts%2FyourPosts/3');
將返回
'http://localhost/posts/subscriptions/3'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.