javascript:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
$(function() {
//
$('#button_submit').click(function() {
var start_date = $('start_date').val();
var end_date = $('end_date').val();
var type = $('type').val();
alert(start_date);
});
});
//
function drawChart() {
var jsonData = $.ajax({
url: "visits/day.php?start_date=" + start_date + "&end_date=" + end_date,
dataType: "json",
async: false
}).responseText;
var obj = jQuery.parseJSON(jsonData);
var data = google.visualization.arrayToDataTable(obj);
var options = {
title: 'Number of visitors'
};
if (type === 'pie') {
var chart = new google.visualization.PieChart(
document.getElementById('chart_div'));
chart.draw(data, options);
}
if (type === 'bar') {
var chart = new google.visualization.BarChart(
document.getElementById('chart_div'));
chart.draw(data, options);
}
}
html:
<form id="myForm">
<input type="text" name="start_date" id="start_date"><br />
<input type="text" name="end_date" id="end_date"><br />
<input type="text" name="type" id="type"><br />
<input type="button" id="button_submit" value="go">
</form>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
通过表单获得的变量似乎是空的,我做了那个 alert(start_date) 并说:未定义并且没有通过 url:visits/day.php?start_date...
我需要在不刷新页面的情况下为我的 php 页面发送这些值
我究竟做错了什么?