2013-10-06 41 views
0

很容易例如:是否有可能得到哪個標籤加載Ajax頁面沒有GET?

<div id="tabs"> 
    <ul> 
    <li><a href="tab_index.php" id="ctx-1">Tab 1</a></li> 
    <li><a href="tab_index.php" id="ctx-5">Tab 2</a></li> 
    </ul> 
    <div class="tabs-spacer" style="height:0px"></div> 
</div> 

而現在的問題:我想知道哪些選項卡「呼叫」 tab_index.php。

最簡單的解決方案是:tab_index.php?ctx = 1,但我不想使用GET出於安全原因。

完全可能嗎?

的小提琴:http://jsfiddle.net/Sledgehammer/M8jYA/

+3

您能解釋一下這些安全問題嗎?它是'GET'有或沒有查詢字符串... –

+0

是的,當然它的GET,但我不想通過url –

+0

參數CTX所以你從誰試圖隱藏這個參數,爲什麼我的問題。當你說你想知道哪個選項卡「調用」它時,安全地假設你的意思是你想讓你的'tab_index.php'有這個信息?正如在下面的答案,它很容易只是添加一個點擊處理程序來記錄此標籤點擊... –

回答

0

如果你不想使用GET,你可以使用POST:

<div id="tabs"> 
    <ul> 
     <li> 
      <form action="tab_index.php" method="POST"> 
       <input type="submit" value="Tab1" name="tab" /> 
      </form> 
     </li> 
     <li> 
      <form action="tab_index.php" method="POST"> 
       <input type="submit" value="Tab2" name="tab" /> 
      </form> 
     </li> 
    </ul> 
    <div class="tabs-spacer" style="height:0px"></div> 
</div> 

演示http://jsfiddle.net/KTmga/(檢查瀏覽器的網絡控制檯)

+0

但它不會在jquery標籤中工作...看看這裏:http://jsfiddle.net/Sledgehammer/M8jYA/ –

1

你可以綁定點擊你的標籤鏈接$('a[href="tab_index.php"]')

$(function() { 
    $('a[href="tab_index.php"]').click(function(){ 
     var clickedTab = $(this).attr("id")); 
    }); 
}); 

jsFiddle示例 - http://jsfiddle.net/Zdw37/6/

+0

不錯(我會用在其他地方),但我需要在tab_index.php中這樣的東西,而不是在主腳本。 –

相關問題