【发布时间】:2012-08-29 05:29:37
【问题描述】:
如果我有一个像 "/api/User/Details/2c021192-25cb-43e1-9bba-3bd5604a0a3d" 这样的 URL,那么从 URL 客户端获取 ID "2c02ds92-25cb-43e1-9bba-3bd5604a0a3d" 的最佳方法是什么?
我需要能够使用 ID 构建 $.getJSON 请求,并且我正在寻找使用 JavaScript、jQuery 等最简洁的方法。谢谢
$.getJSON('/api/User/2c021192-25cb-43e1-9bba-3bd5604a0a3d')...
【问题讨论】:
-
这是非常基本的。在字符串上查找
.split函数。 -
是当前的 url(如运行时在地址栏中)还是代码中某处或文本字段中的 url?
-
最简单的方法是使用
.lastIndexOf或indexOf with string starting from -1然后url.substring(lastFwdSlashIndex + 1) -
有一个plugin here 可能会有所帮助
标签: javascript jquery asp.net-web-api