如何使用JavaScript通过GET方法将url参数发送到PHP?

如何使用JavaScript通过GET方法将url参数发送到PHP?,php,javascript,Php,Javascript,这是我的JS代码 function da(){ var a=document.forms["user"]["age"].value; if(this.age.value < 18 || this.age.value > 85) { alert('some text...'); this.age.focus(); return false; }else{ window.location.href='

这是我的JS代码

function da(){
    var a=document.forms["user"]["age"].value;
    if(this.age.value < 18 || this.age.value > 85) {
        alert('some text...');
        this.age.focus();
        return false;
    }else{
        window.location.href='file.php?&'+a;
    }
}
函数da(){
var a=文档.forms[“用户”][“年龄”].值;
如果(this.age.value<18 | | this.age.value>85){
警报('某些文本…');
这个.age.focus();
返回false;
}否则{
window.location.href='file.php?&'+a;
}
}
它只是将参数传递到我所在的页面。。。 这是表格以防万一(我是初学者,请记住)

一些文本时代
Aj2功能不是这里的问题。。。
谢谢你对我的帮助…

像这样的事情我不是专家

$('button name').on('click', function() {
   var age_ = document.getElemenetById('age');
   $.get('path of your file', {'age' : age_}, function(resp) {
        // code to pass parameter
        alert(age_);
   });
});

只是想一想,如果您实际上不需要重新加载页面,只需要从PHP获取javascript代码的信息,您可以执行以下操作

<script>

<?
    $phpvariable = "my variable";
?>

var jsvariable = <?php echo json_encode($phpvariable); ?>;

</script>

var-jsvariable=;
现在,javascript变量jsvariable将保存PHP变量的内容。

用于此。。。。AJAX现在谷歌。可能重复的
<script>

<?
    $phpvariable = "my variable";
?>

var jsvariable = <?php echo json_encode($phpvariable); ?>;

</script>