如何使用ajax将变量发布到php文件

如何使用ajax将变量发布到php文件,php,jquery,html,ajax,Php,Jquery,Html,Ajax,我想将一个变量传递到college.php,该变量可用于获取数据 我已经尝试了使用表单的get和post方法,但使用get后,变量值在地址栏中可见,并显示使用get表单重新提交警报 这是我用过的 <form class="morestories"method="get" enctype="multipart/form-data" action="college.php"> <input type="hidden" name="college

我想将一个变量传递到college.php,该变量可用于获取数据

我已经尝试了使用表单的
get
post
方法,但使用
get
后,变量值在地址栏中可见,并显示使用get表单重新提交警报 这是我用过的

<form class="morestories"method="get" enctype="multipart/form-data" action="college.php">

                  <input type="hidden" name="collegename" value="<?php $collegename=$row['name']; echo $collegename; ?>">

                  <input class="morestoriesbutton" type="submit" name="collegeselectlink" value="More Stories" />

                </form>


这是一个向php函数传递名称和密码的示例, 您可以参考此信息,并根据您的情况进行相应的应用

$(document).ready(function(){ 
    //this is my button 
    $("#click").click(function(){  
        // getting username and password from my html
        username = $("#name").val();
        password = $("#pad").val();

        if(username=="" || password==""){
            alert("please check the details");
        } else {
            $.ajax({ url: 'reverse.php',
                data: {username:username,password:password},
                type: 'post',
                success: function(output) {
                     alert(output);
                }
            });
        }
    });
});

问题不清楚。你能具体说明一下你想在这里完成什么吗?在你的代码中,你从ajax请求中获得输出,但我希望单击函数重定向到college.php,其中使用传递的变量获取数据@shivkumarp请查看ajax中的url.specity函数名和url,它可能会有帮助,如:url:'ABC.php?方法=XYZ',