2015-12-21 54 views
0

我在網站上工作,它是一個傳呼機,但它動態加載內容,我希望能夠深入鏈接到該內容。使用jQuery清理網址

有沒有一種方法,使用jQuery,我可以重寫我的網址,以獲取該格式 http://www.example.com/site1/content1

我需要獲得VAR「SITE1」,以確定在網頁上應該加載,類似於使用# site1

而'content1'用於確定將在site1頁面上顯示哪些內容。

+0

什麼是後端? C#或PHP? –

+0

目前還沒有,但它會是PHP – stmp

+0

您應該查看crossroadjs和hasherjs – EoiFirst

回答

0

你想找的是URL路由
基本上URL路由讓你的網址,相當多的有意義的 例如

index.php?action=search&type=book&author=fitzgerald 

這就是初始狀態,如果你不航線您的網址

/search/book/ftizgerald 

這就是你路由你的網址時的樣子:

既然你說過你想用php。 那麼這可能會有所幫助。

function getCurrentUri() 
    { 
     $basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/'; 
     $uri = substr($_SERVER['REQUEST_URI'], strlen($basepath)); 
     if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?')); 
     $uri = '/' . trim($uri, '/'); 
     return $uri; 
    } 

    $base_url = getCurrentUri(); 
    $routes = array(); 
    $routes = explode('/', $base_url); 
    foreach($routes as $route) 
    { 
     if(trim($route) != '') 
      array_push($routes, $route); 
    } 

    /* 
    Now, $routes will contain all the routes. $routes[0] will correspond to first route. For e.g. in above example $routes[0] is search, $routes[1] is book and $routes[2] is fitzgerald 
    */ 

    if($routes[0] == 「search」) 
    { 
     if($routes[1] == 「book」) 
     { 
      searchBooksBy($routes[2]); 
     } 
    }