<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>TEST</title>
<script type="text/javascript" src="js/echarts.js"></script>
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
</head>
<body>
<input type="text" id="username">
<input type="text" id="password">
<button id="sub">查询</button>
<span id="text"></span>
<div id="main" style="height:400px"></div>
<script type="text/javascript">
$(document).ready(function(){
$("#sub").on("click",function(){
var myChart = echarts.init(document.getElementById('main'));
var arr1=[],arr2=[];
function arrTest(){
var username=$('#username').val();
var password=$('#password').val();
$.ajax({
type:"post",
async:false,
url:"json.php",
result:{username:username,password:password},
dataType:"json",
success:function(result){
if (result) {
for (var i = 0; i < result.length; i ) {
arr1.push(result[i].name);
arr2.push(result[i].age);
}
}
}
})
return arr1,arr2;
}
arrTest();
var option = {
tooltip: {
show: true
},
legend: {
data:['age']
},
xAxis : [
{
type : 'category',
data : arr1
}
],
yAxis : [
{
type : 'value'
}
],
series : [
{
"name":"age",
"type":"bar",
"data":arr2
}
]
};
myChart.setOption(option);
});
});
</script>
</body>
后台
//$p = $_GET["username"];
$p="20180621";
用$p = $_GET["username"]接收不到前端传来的数据,但是直接赋值给变量$p,前端能正常收到json数据
威尼斯2018-06-27 09:02:55
Is your ajax type not post? Why does the background use $_GET to receive it? Use $_REQUEST or $_POST.