
html前台填写用户名密码邮箱 怎么通过ajax传到后台php的三个变量上? 求大神写个好理解的简单例子
1个回答
展开全部
html前台:
<script type="text/javascript" src="jquery.min.js"></script>
<script>
$.ajax({
type:'POST',
url:'CH_EN.php',
data:{'username':'name1','password':'123456','email':'test@126.com'},
dataType:"json",
success:function(rep){
alert(rep.code);
}
})
</script>
php后台
header("Content-type: text/json; charset=utf-8");
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
<script type="text/javascript" src="jquery.min.js"></script>
<script>
$.ajax({
type:'POST',
url:'CH_EN.php',
data:{'username':'name1','password':'123456','email':'test@126.com'},
dataType:"json",
success:function(rep){
alert(rep.code);
}
})
</script>
php后台
header("Content-type: text/json; charset=utf-8");
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? $_POST['password'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
更多追问追答
追问
能用GET的方法吗?
追答
可以的type:'POST',
type:'GET',
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询