首页 > 解决方案 > 如何在getJson中将td作为参数传递?

问题描述

$("td").click(function(){
    $.getJSON(
        'http://example.com/customer/get_all_vehicle_by_name/?vehicle_name=' + $("td"),
        function(data) {
        }

如何将td值传递给 url?

标签: jquery

解决方案


用于$(this).text()获取内容td并在获取内容后将其td附加到您希望获取 JSON 以供使用的 URL$.getJSON()

$("td").click(function(){
  var tdContent = $(this).text();
  //append this td text in the url
  var url = 'http://192.168.1.4:8080/customer/get_all_vehicle_by_name/?vehicle_name='+ tdContent
  console.log(url);
  //invoke this
  //$.getJSON(url, function(data){});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <td>Cell A</td>
    <td>Cell B</td>
  </tr>
</table>


推荐阅读