我需要 JS/jQuery 中的路径名(www.my-site.com/this-part/and-this-part/etc/ ),但我需要它作为字符串而不是对象。
换句话说,我需要$_SERVER['REQUEST_URI'];
JS/jQuery。
我试过了:
var page_pathname = location.pathname;
var page_pathname = location.pathname + location.search;
var page_pathname = (location.pathname+location.search).substr(1);
我得到的一切console.log
:
1. Object {error: Object}
2. Location {hash: "", search: "", pathname: "/my-cat/my-title/", port: "", hostname: "www.my-site.com"…}
我需要什么console.log
:my-cat/my-title/