dongxin1999 2017-03-30 13:05
浏览 272

ERROR主线程上的同步XMLHttpRequest已弃用

I am attempting to load a graph with options to show data between select dates. When I run it on my webpage, I get an error "Table has no columns." 1, but when i set the IF statement (buildchris) to NOT EQUAL to maincampus, the chart will load. I believe it has something to do with the xmlhttp .send, the variables seem to not be sending over POST (buildingchartchris). Does anyone have a solution to this problem?

buildchris.php

<?php
session_start(); // Start the session.

// If no session value is present, redirect the user:
// Also validate the HTTP_USER_AGENT!
if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) OR ($_SESSION['admin_level'] < 1) )
{
    // Need the functions:
    require ('includes/login_functions.inc.php');
    redirect_user('index.php');
}
require("includes/mysqli_connect.php");


$p = $_POST['purpose'];

if($p == "maincampus")
{

    $sm = $_POST['sm'];
    $sd = $_POST['sd'];
    $sy = $_POST['sy'];
    $em = $_POST['em'];
    $ed = $_POST['ed'];
    $ey = $_POST['ey'];

    //$start_date = Date("Y-m-d", mktime(0, 0, 0, $sm, $sd, $sy));
    //$end_date = Date("Y-m-d", mktime(0, 0, 0, $em, $ed, $ey));    
    $start_date= "2014-01-01";
    $end_date= "2016-01-01";

$result = $dbc->query('SELECT SUM(actual_hours) as act_hours,      Buildings.bld_name, Buildings.bld_location FROM work_orders INNER JOIN Buildings ON work_orders.building = Buildings.bld_no WHERE work_orders.actual_completion_date > "'.$start_date.'" AND work_orders.actual_completion_date < "'.$end_date.'" AND Buildings.bld_location ="0" AND Buildings.bld_name <> "N/A" AND work_orders.actual_completion_date IS NOT NULL GROUP BY Buildings.bld_name');






$rows = array();
$table = array();
$table['cols'] = array(



array('label' => 'Building', 'type' => 'string'),
array('label' => 'Hours', 'type' => 'number')

);
/* Extract the information from $result */
foreach($result as $r) {

  $temp = array();

  // The following line will be used to slice the Pie chart

  $temp[] = array('v' => (string) $r['bld_name']); 

  // Values of the each slice

  $temp[] = array('v' => (int) $r['act_hours']); 
  $rows[] = array('c' => $temp);
}

$table['rows'] = $rows;

// convert data into JSON format
$jsonTable = json_encode($table);


echo $jsonTable;
}

?>

buildingchartchris.php

<?php
session_start(); // Start the session.

// If no session value is present, redirect the user:
// Also validate the HTTP_USER_AGENT!
if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] !=     md5($_SERVER['HTTP_USER_AGENT'])) OR ($_SESSION['admin_level'] < 1) )
{
    // Need the functions:
    require ('includes/login_functions.inc.php');
    redirect_user('index.php');
}
require("includes/mysqli_connect.php");

$page_title = 'Dashboard';
include ('includes/header.html');   


?>


<html>
<head>
<title>Dashboard</title>
<link rel="icon" href="images/NKU.png" type="image/png" sizes="16x16"> 
<link rel="stylesheet" href="includes/as.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js?libraries=geometry"></script>
<script src="http://maps.google.com/maps/api/js"></script>
<script>
<!--

    //hides or shows the table given by nm      
    function hide_table(nm)
    {   
    //  alert(is_fullscreen);
        var table_selector = "#table_" + nm;
        $(table_selector).toggle();
        //table_width = (table_width == 24)? 35:24;
        //$("#iframeholder").animate({width: table_width + "%"});
    }
// -->
</script> </head>
<div id="content">


<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<!--Load the Ajax API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">




// Set a callback to run when the Google Visualization API is loaded.
// google.setOnLoadCallback(drawChart);

function drawChart() {

    var maincamp_sm, maincamp_sd, maincamp_sy, maincamp_em, maincamp_ed, maincamp_ey;

    if( document.getElementById("maincamp_dates_quarter").checked )
    {
        var maincamp_q = document.getElementById("maincamp_quarter").value;
        maincamp_ey = Number(document.getElementById("maincamp_quarter_year").value);
        maincamp_sy = maincamp_ey;

        if( maincamp_q == 0 )
        {
            maincamp_sm = 7;
            maincamp_sd = 1;
            maincamp_em = 6;
            maincamp_ed = 30;
            maincamp_ey = maincamp_ey + 1;              
        }
        else if( maincamp_q == 1)
        {
            maincamp_sm = 7;
            maincamp_sd = 1;
            maincamp_em = 9;
            maincamp_ed = 30;       
        }
        else if( maincamp_q == 2 )
        {
            maincamp_sm = 10;
            maincamp_sd = 1;
            maincamp_em = 12;
            maincamp_ed = 31;               
        }
        else if( maincamp_q == 3 )
        {
            maincamp_sm = 1;
            maincamp_sd = 1;
            maincamp_em = 3;
            maincamp_ed = 31;
            maincamp_ey = maincamp_ey + 1;
            maincamp_sy = maincamp_sy + 1;
        }
        else if( maincamp_q == 4 )
        {
            maincamp_sm = 4;
            maincamp_sd = 1;
            maincamp_em = 6;
            maincamp_ed = 30;
            maincamp_ey = maincamp_ey + 1;
            maincamp_sy = maincamp_sy + 1;
        }
    }
    else
    {
        maincamp_sm = document.getElementById("maincamp_start_month").value;
        maincamp_sd = document.getElementById("maincamp_start_day").value;
        maincamp_sy = document.getElementById("maincamp_start_year").value;
        maincamp_em = document.getElementById("maincamp_end_month").value;
        maincamp_ed = document.getElementById("maincamp_end_day").value;
        maincamp_ey = document.getElementById("maincamp_end_year").value;
    }

    if(!( (maincamp_ey < maincamp_sy) || ( (maincamp_em < maincamp_sm) && (maincamp_ey == maincamp_sy) ) || ( (maincamp_ed < maincamp_sd) && (maincamp_em == maincamp_sm) && (maincamp_ey == maincamp_sy) ) ))
    {
        var xmlhttp;
        xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.onreadystatechange = function()//Function called when there is a change of state for the server
        {                                      //request
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)//when request is complete and no issues
            {

                //var str = xmlhttp.responseText;

            var jsonData = $.ajax({
            url: "buildchris.php",
            type: "POST",
            dataType: "json", // type of data we're expecting from server
            async: false // make true to avoid waiting for the request to be complete
          });



  // Create our data table out of JSON data loaded from server.
  var data = new google.visualization.DataTable(jsonData.responseText);
  var options = {
       title: 'Labor Hours for Main Campus',
      is3D: 'true',
      width: 1200,
      height: 2000,
      chartArea:{width:"40%"},
      bar: {groupWidth: "50%"}
    };


    var maincamp_view = new google.visualization.DataView(data);
  // Instantiate and draw our chart, passing in some options.
  // Do not forget to check your div ID
  var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
  chart.draw(maincamp_view, options);
}   
        };
        xmlhttp.open("POST","buildchris.php",true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("purpose=maincampus&sm=" + maincamp_sm + "&sd=" + maincamp_sd + "&sy=" + maincamp_sy + "&em=" + maincamp_em + "&ed=" + maincamp_ed + "&ey=" + maincamp_ey);
    }

    else
    {
        alert("Your end date cannot be before the start date.");
    }
}

  google.load('visualization', '1', {'packages':['corechart']});

function cursor_hand(x)
{
    x.style.cursor = "pointer";
}

function cursor_default(x)
{
    x.style.cursor = "default";
}

function hide_element(nm)
{
    var table_selector = "#" + nm;
    $(nm).toggle(); 
}
</script>

<body>
<p onclick = "hide_element(operational_effectiveness_div);" style = "text-decoration: underline; font-size:x-large; font-weight:bold;" onmouseover="cursor_hand(this)" onmouseout="cursor_default(this)">Operational Effectiveness Reports</p><br>
<div id = "operational_effectiveness_div" >

<p onclick = "hide_element(maincamp_div);" style = "text-indent: 15px; text-decoration: underline;" onmouseover="cursor_hand(this)" onmouseout="cursor_default(this)">Show Total Labor Hours for Main Campus 2015-16</p><br>
    <div id = "maincamp_div" style = "display:table;">
        <fieldset style = "width: 800px; margin:auto; margin-left: 200px;"><legend><input type = "radio" id = "maincamp_dates_quarter" name = "maincamp_dates" value = "1" checked> Report by quarter </legend>
            <p><select id = "maincamp_quarter">
                <option value = 0 selected>All Quarters</option>
                <option value = 1>Q1</option>
                <option value = 2>Q2</option>
                <option value = 3>Q3</option>
                <option value = 4>Q4</option>
            </select>
            <input type = "number" id = "maincamp_quarter_year" min = "2015" value = "2015"></p>
        </fieldset><br>
        <fieldset style = "width: 800px; margin:auto; margin-left: 200px;"><legend><input type = "radio" id = "maincamp_dates_range" name = "maincamp_dates" value = "2"> Custom date range </legend>
            <p>Start date (mm-dd-yyyy): <input type = "number" id = "maincamp_start_month" min = "1" max = "12" value = "1"><input type = "number" id = "maincamp_start_day" min = "1" max = "31" value = "1"><input type = "number" id = "maincamp_start_year" min = "2015" value = "2015"></p>
            <p>End date (mm-dd-yyyy): <input type = "number" id = "maincamp_end_month" min = "1" max = "12" value = "1"><input type = "number" id = "maincamp_end_day" min = "1" max = "31" value = "1"><input type = "number" id = "maincamp_end_year" min = "2015" value = "2016"></p>
        </fieldset>
        <br>
        <p onclick = "drawChart()" style = "border: thin solid black; padding: 2px; width: 95px; margin-left: 550px;" onmouseover="cursor_hand(this)" onmouseout="cursor_default(this)">Generate report</p>
        <div id="chart_div" style="width: 1000px; text-indent: 50px;"></div>
    </div>
        </div>
   </body>
</html>
<?php


//Release the used resources        
mysqli_close($dbc);     
include ('includes/footer.html');
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度