Javascript 使用ajax将图表页面调用到另一个页面
我在用ajax。我必须使用ajax在另一个名为index.php的页面中调用一个名为chart.php的页面。当我运行index.php时,chart.php文件未被调用且不工作。但是如果我只运行chart.php,它就可以工作了。所以我认为编码是完美的。。但我还是找不到错误 index.phpJavascript 使用ajax将图表页面调用到另一个页面,javascript,php,jquery,ajax,morris.js,Javascript,Php,Jquery,Ajax,Morris.js,我在用ajax。我必须使用ajax在另一个名为index.php的页面中调用一个名为chart.php的页面。当我运行index.php时,chart.php文件未被调用且不工作。但是如果我只运行chart.php,它就可以工作了。所以我认为编码是完美的。。但我还是找不到错误 index.php <head> <script> function selectMonth(str) { if (str=="") { document.getElemen
<head>
<script>
function selectMonth(str) {
if (str=="") {
document.getElementById("month").innerHTML ="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("month").innerHTML =xmlhttp.responseText;
}
}
xmlhttp.open("GET","chart.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="col-lg-3">
<select class="form-control" name="month" onChange="selectMonth(this.value)">
<option value="01">January </option>
<option value="02">February</option>
<option value="03">March </option>
<option value="04">April </option>
<option value="05">May </option>
<option value="06">June </option>
<option value="07">July </option>
<option value="08">August </option>
<option value="09">September </option>
<option value="10">October </option>
<option value="11">November </option>
<option value="12">December </option>
</select>
</div>
<div id="month"></div>
</body>
//.css,.js are connected well.
<?php
$month=(int)$_GET['q'];
include 'inc/connection.php';
$sql_month="SELECT SUM(payment_value) AS pay,pay_date From payment WHERE MONTH(pay_date)=$month";
$sql_month_run=mysqli_query($con,$sql_month);
$c=0;
?>
<head>
<script type="text/javascript">
$(function() {
Morris.Donut({
element: 'morris-donut-month',
data: [],
resize: true
});
Morris.Line({
element: 'morris-line-month',
data: [
<?php
while($row_month=mysqli_fetch_array($sql_month_run)) {
$results_month[]="{d: "."'".$row_month['pay_date']."'".","."payment: ".$row_month['pay']."}, ";
echo $results_month[$c++];
}
?>
],
// The name of the data record attribute that contains x-visitss.
xkey: 'd',
// A list of names of data record attributes that contain y-visitss.
ykeys: ['payment'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Paid'],
// Disables line smoothing
smooth: false,
resize: true
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="clearfix"></div>
<div class="col-lg-12">
<div class="panel panel-red">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-long-arrow-right"></i>Monthly Payment Graph</h3>
</div>
<div class="panel-body">
<div id="morris-line-month"></div>
<div id="morris-donut-month"></div>
<div class="text-right">
<a href="#">View Details <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
函数selectMonth(str){
如果(str==“”){
document.getElementById(“月”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“月”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“chart.php?q=“+str,true”);
xmlhttp.send();
}
一月
二月
前进
四月
也许
六月
七月
八月
九月
十月
十一月
十二月
chart.php
<head>
<script>
function selectMonth(str) {
if (str=="") {
document.getElementById("month").innerHTML ="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("month").innerHTML =xmlhttp.responseText;
}
}
xmlhttp.open("GET","chart.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="col-lg-3">
<select class="form-control" name="month" onChange="selectMonth(this.value)">
<option value="01">January </option>
<option value="02">February</option>
<option value="03">March </option>
<option value="04">April </option>
<option value="05">May </option>
<option value="06">June </option>
<option value="07">July </option>
<option value="08">August </option>
<option value="09">September </option>
<option value="10">October </option>
<option value="11">November </option>
<option value="12">December </option>
</select>
</div>
<div id="month"></div>
</body>
//.css,.js are connected well.
<?php
$month=(int)$_GET['q'];
include 'inc/connection.php';
$sql_month="SELECT SUM(payment_value) AS pay,pay_date From payment WHERE MONTH(pay_date)=$month";
$sql_month_run=mysqli_query($con,$sql_month);
$c=0;
?>
<head>
<script type="text/javascript">
$(function() {
Morris.Donut({
element: 'morris-donut-month',
data: [],
resize: true
});
Morris.Line({
element: 'morris-line-month',
data: [
<?php
while($row_month=mysqli_fetch_array($sql_month_run)) {
$results_month[]="{d: "."'".$row_month['pay_date']."'".","."payment: ".$row_month['pay']."}, ";
echo $results_month[$c++];
}
?>
],
// The name of the data record attribute that contains x-visitss.
xkey: 'd',
// A list of names of data record attributes that contain y-visitss.
ykeys: ['payment'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Paid'],
// Disables line smoothing
smooth: false,
resize: true
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="clearfix"></div>
<div class="col-lg-12">
<div class="panel panel-red">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-long-arrow-right"></i>Monthly Payment Graph</h3>
</div>
<div class="panel-body">
<div id="morris-line-month"></div>
<div id="morris-donut-month"></div>
<div class="text-right">
<a href="#">View Details <i class="fa fa-arrow-circle-right"></i></a>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
/.css、.js连接良好。
$(函数(){
莫里斯,甜甜圈({
元素:“莫里斯甜甜圈月”,
数据:[],
调整大小:true
});
莫里斯线({
元素:“莫里斯线月”,
数据:[
],
//包含x-visitss的数据记录属性的名称。
xkey:'d',
//包含y-Visits的数据记录属性的名称列表。
ykeys:[“付款”],
//当您将鼠标悬停在
//图表。
标签:[“已付”],
//禁用线平滑
平滑:假,
调整大小:true
});
});
每月付款图
运行代码时,您是否在浏览器控制台中查找错误?是的。我看了看。但是没有错误@jayblanchard在请求/响应中呢?对不起,我是ajax新手。我找不到它。你能帮我打开你浏览器的开发工具吗。在那里你应该看到一个网络标签或类似的东西。点击该按钮并提出请求。您应该会看到传出的请求和传入的响应。您是否在运行代码时查看了浏览器控制台中的错误?是的。我看了看。但是没有错误@jayblanchard在请求/响应中呢?对不起,我是ajax新手。我找不到它。你能帮我打开你浏览器的开发工具吗。在那里你应该看到一个网络标签或类似的东西。点击该按钮并提出请求。您应该看到传出的请求和传入的响应。