2010-04-26 61 views
0
<div class="lead_detail_box_routing"> 


<div class="lead_detail_box_left">location 1</div> 
<div class="lead_detail_box_right">Route</div> 
<div class="lead_detail_box_left">location 2</div> 
<div class="lead_detail_box_right">Route</div> 
<div class="lead_detail_box_left">location 3</div> 
<div class="lead_detail_box_right">Route</div> 
<div class="lead_detail_box_left">location 4</div> 
<div class="lead_detail_box_right">Route</div> 

<div id="results" style="text-align:center;"></div> 

</div>  <!-- end lead_detail and routing--> 

例如,當用戶點擊「路線」我希望我的jQuery的手動routing.php獲得「3」 ..用jquery檢索變量ajax

到目前爲止我有:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("a#route").click(function() { 
      $("#results").load("jquery-manual-routing.php", { route_to: ???? }); 
      return false; 
     }); 
    });  
    </script> 

所以在我的PHP腳本,當用戶在route點擊旁邊location 3我希望能夠抓住$_GET['route_to'] =3;

另外請注意,我的表已分配的,因爲我使用的CSS樣式它

答案將是純PHP的回聲

0123類
+0

顯示您的HTML。另外,您將如何處理服務器響應,以及響應的內容類型(XML,JSON,HTML等)? – 2010-04-26 19:45:31

回答

0
$(document).ready(function() { 
    $("a#route").click(function(event) { 
     link = $(event.target); 

     $("#results").load("jquery-manual-routing.php", { route_to: link.text() }); 

     return false; 
    }); 
}); 

這將在錨標籤的網址與實際鏈接調用jquery-manual-routing.php?route_to=location 3

1

填充你需要再覆蓋默認點擊動作與jQuery函數

<a class="route" href="jquery-manual-routing.php?route_to=1">route to destination 1</a><br/> 
<a class="route" href="jquery-manual-routing.php?route_to=2">route to destination 2</a><br/> 
<a class="route" href="jquery-manual-routing.php?route_to=3">route to destination 3</a><br/> 
<a class="route" href="jquery-manual-routing.php?route_to=4">route to destination 4</a> etc... 

<script type="text/javascript"> 
    $("a.route").live('click', function() { // live is better 
     $("#results").load($(this).attr('href')); 
     return false; 
    }); 
</script> 
+0

即時得到: 錯誤:缺少)後的參數列表 源文件:lead_detail.php lead_id = 68443 嗎?行:139,柱:49 源碼: $( 「#結果」)負載($(本).attr('href')}); – vick 2010-04-26 20:02:10

+0

工作得很好,謝謝大家! 當ajax被調用時,有人會「等待加載」div,這會很好嗎? – vick 2010-04-26 20:22:51

0

如果由HTML去您提供了這是一個可能的解決方案:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("div.lead_detail_box_right").click(function() { 
      $("#results").load("jquery-manual-routing.php", { route_to: $(this).prev().text().replace("location ", "") }); 
     }); 
    });  
</script> 

抓住previous元素並獲取文本中的數字。我用replace,您還可以使用split

0

充分利用文字數量:(被點擊的格)

$(this).text().replace(/.*?(\d+)$/, '$1') 

從div的位置獲得它:

$('.lead_detail_box_left').index(this) + 1