我的网页网址为https://test.com/deaileditem.php?id=5
我需要获取此ID并在我的ajax请求结束时附加以获取json数据。
我使用代码
var id = window.location.href.split('=').pop()
console.log(id)
我的vue js代码是
<script>
still = new Vue({
el: '#cat',
data: {
les: [],
},
mounted() {
var m = this;
var id = window.location.href.split('=').pop()
console.log(id)
$.ajax({
url: "https://text.com/post/get/id",
type: "GET",
dataType: "JSON",
success: function(e) {
m.les = e;
console.log(e.les)
},
});
},
})
</script>
而不是&#39; id&#39;在网址中(网址:&#34; https://text.com/post/get/id&#34;)。我需要附上我获得的id,以便新的url是(url:&#34; https://text.com/post/get/5&#34;)。如何能够获取获取所需的json数据的id。我在js非常基础。请帮帮我
答案 0 :(得分:1)
您尚未在id
url
更改
url: "https://text.com/post/get/id",
到
url: "https://text.com/post/get/" + id,