Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 JSON 新手。我正在研究一个领域,该领域需要我找出发送 JSON 请求的 URL 和返回 JSON 响应之间的关系。我想在应用程序中唯一标识哪个 URL 调用其对应的 JSON。请帮助我或指出我正确的方向。提前致谢。
您可以简单地附加window.location.pathname:
window.location.pathname
json = {somedata: 'foo', url: window.location.pathname };
如果您需要整个 URL,而不仅仅是路径,请使用href而不是。pathname
href
pathname
请注意,JSON 是一种协议,并不特定于 jQuery(或 JavaScript,尽管它可能是最常见的用法)。