用js获取浏览器的url,然后如何把这个url传给php
jquery代码:$.get("test.php?domain="+document.domain+"",function(data,status){
console.log(data);
});PHP代码:
<?php
$domain = isset($_GET['domain']) ? $_GET['domain'] : '';
$arr = array ('message'=>'你的域名是:'.$domain);
echo json_encode($arr);<?php
$domain = isset($_GET['domain']) ? $_GET['domain'] : '';
if(!empty($domain))
{
$arr = array('message'=>$domain);
echo json_encode($arr);
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>test</title>
</head>
<body>
<script src="jquery.min.js"></script>
<script>
$.get("?domain="+document.domain+"",function(data,status){
alert(data.message);
}, 'json');
</script>
</body>
</html>
<?php
}
?>
页:
[1]