PHP 怎么处理前端发过来AJAX json数据,求大神指点
前端$("#logon").click(function(){varuser=$("forminput[name=UserName]").val();varpass=$(...
前端
$("#logon").click(function(){
var user = $("form input[name=UserName]").val();
var pass = $("form input[name=Password]").val();
if(user ==="" | pass=="" ){
alert("请输入用户名或者密码");
}else{
var jsonsData = {
"action":"Logon",
"user":user,
"pass":pass
};
$.ajax({
"url":"Logon.php",
"type":"POST",
"data": jsonsData,
"dataType":"json",
"error":function(xml,error){
alert(error);
},
后端
<?php
include("Server.php");
$Type = isset($_POST['action'])?$_POST['action']:'';
$userName = isset($_POST['user'])?$_POST['user']:'';
//echo json_encode($Type);
echo $Type;//输出没数据
//用echo json_encode($Type);为空但前端能接收到 Logon
//想把userName写到SQL语句里面,但$userName为空 展开
$("#logon").click(function(){
var user = $("form input[name=UserName]").val();
var pass = $("form input[name=Password]").val();
if(user ==="" | pass=="" ){
alert("请输入用户名或者密码");
}else{
var jsonsData = {
"action":"Logon",
"user":user,
"pass":pass
};
$.ajax({
"url":"Logon.php",
"type":"POST",
"data": jsonsData,
"dataType":"json",
"error":function(xml,error){
alert(error);
},
后端
<?php
include("Server.php");
$Type = isset($_POST['action'])?$_POST['action']:'';
$userName = isset($_POST['user'])?$_POST['user']:'';
//echo json_encode($Type);
echo $Type;//输出没数据
//用echo json_encode($Type);为空但前端能接收到 Logon
//想把userName写到SQL语句里面,但$userName为空 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询