jquery - 如何在getJson中将td作为参数传递?
问题描述
$("td").click(function(){
$.getJSON(
'http://example.com/customer/get_all_vehicle_by_name/?vehicle_name=' + $("td"),
function(data) {
}
如何将td
值传递给 url?
解决方案
用于$(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>
推荐阅读
- git - Azure devops - git repo 同步
- javascript - 尝试在多个选项卡中同步访问令牌的竞争条件
- symfony - 删除具有两个 OneToOne 关系的实体
- redux - Saga Setup,未执行 fetch
- xml - 我的 XSLT 提取与节点值对应的值有什么问题?
- perl - 在不遍历整个哈希的情况下查找子哈希中的密钥
- c# - 有没有办法在不解压缓冲区(C++/CLR)的情况下使用 CredUIPromptForWindowsCredentialsW?
- sql - 有没有办法根据 R 中的一组条件使用表 T2 中的列 B 更新表 T1 中的列 A?
- python-3.x - python3中的随机模块不可调用错误
- python - 杀死正在运行 Gstreamer 的子进程