在javascript中从URL路径getJSON Api获取最后一个文件夹名称

时间:2017-09-24 17:02:16

标签: javascript jquery json

如何从URL路径000000获取最后一个文件夹名称

网址路径:

http://www.mywebsite.com/#/000000

Html代码:

<html>

<body>
  <p id="link"></p>

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
var aaa = "https://www.example.com/";
var bbb = "last folder name from URL path";
$.getJSON(aaa+bbb, function(data) {
  document.getElementById("link").innerHTML = data.url;
});

alert(aaa+bbb);

</script>

</body>
</html>

我想要这样的结果:

$.getJSON("https://www.example.com/000000", function(data)
alert(https://www.example.com/000000)

1 个答案:

答案 0 :(得分:0)

var aaa = "https://www.example.com/";
var bbb = document.location.href.split("#/");
$.getJSON(aaa+bbb[1], function(data) {
  document.getElementById("link").innerHTML = data.url;
});

alert(aaa+bbb[1]);