頁面加載我有一個像/accounts/?status=done
如何獲得GET數據,當前URL時的jQuery
所以在我想要得到的current url
和GET data
般的地位文檔加載URL =做
所以下面是我的代碼可以能得到當前的URL,而不是GET數據
<script>
$(window).load(function() {
//alert("window load occurred!");
var pathname = window.location.pathname;
console.log(pathname);
$.get(pathname,function(data){ console.log(data) });
});
</script>
那麼如何獲取當前URL和GET樣?狀態數據= jQuery中做了頁面加載?
編輯
於是我根據在這裏提供如下,仍然鏈接已經編輯了無法打印的查詢字符串參數
<script>
function getParameterByName(name) {
console.log(name+"......................");
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
$(window).load(function() {
//alert("window load occurred!");
var pathname = window.location.pathname;
console.log(pathname+"hurayyyyy");
console.log(pathname);
var res = getParameterByName(window.location.pathname)
console.log(res+"oooppppppppppppssssssssssss");
});
</script>
結果簡直就像下面
可能dublicate:http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values – caramba
我已經加入一個編輯,請移動讓我朝着正確的方向移動。 –