gpt4 book ai didi

javascript - 如何获取我的GET值?

转载 作者:行者123 更新时间:2023-12-03 10:05:01 26 4
gpt4 key购买 nike

当我访问此链接:http://main.php?valretour=OK时,如何获取valretour的值?

Main.php

我直接在我的 PHP 页面中尝试了这个...:

<script>
alert($_GET['valretour']);
if($_GET['valretour'] == "OK"){
$.toaster({ priority : 'success', title : 'Success', message : 'OK' });
} else {
$.toaster({ priority : 'warning', title : 'Failed', message : 'NOT' });
}
</script>

我的页面main.php

<html>
<head>
<!--Links css-->
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script type='text/javascript' src='jquery/external/jquery/jquery.js'></script>
<script type='text/javascript' src="jquery/jquery-ui.js"></script>
<script src="jquery/jquery.toaster.js"></script>
</head>

<body>
<div id="logo">
<a href="#"><img src="images/logost.png" style="width:180px;height:120px"></a>
</div>
<script src="jquery/external/jquery/jquery.js"></script>
<script src="jquery/jquery-ui.js"></script>

<script>
alert($_GET['valretour']);
if($_GET['valretour'] == "OK"){
$.toaster({ priority : 'success', title : 'Success', message : 'OK' });
} else {
$.toaster({ priority : 'warning', title : 'Failed', message : 'NOT' });
}
alert();
</script>
</body>
</html>

最佳答案

您需要解析location.search:

var query = (function() {
function decode(string) {
return decodeURIComponent(string.replace(/\+/g, " "));
}
var result = {};
if (location.search) {
location.search.substring(1).split('&').forEach(function(pair) {
pair = pair.split('=');
result[decode(pair[0])] = decode(pair[1]);
});
}
return result;
})();


if(query['valretour'] == "OK"){
$.toaster({ priority : 'success', title : 'Success', message : 'OK' });
} else {
$.toaster({ priority : 'warning', title : 'Failed', message : 'NOT' });
}

关于javascript - 如何获取我的GET值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30399714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com