我目前有这样的页面设置:
PHP Variable Declarations
HTML header, then a form to submit GET query
The PHP that processes some stuff based on the GET data
a bit of JavaScript that makes a pretty graph from the retrieved, processed data
我想要做的是在首次加载页面时只显示表单,然后在输入查询时,让图表显示在页面底部。它使用的是flot库,JS目前看起来像这样:
<script id="source" language="javascript" type="text/javascript">
$.plot($("#test"), [ [[0, 0], [1, 1]] ], { yaxis: { max: 1 } });
</script>
我是否需要用某些事件处理程序替换$ .plot?我是一个全新的JS新手!
谢谢!
答案 0 :(得分:2)
我个人使用php(但我对JS很垃圾......所以我有偏见...... =)
<?php
$formSubmitted = $_POST['formSubmitted'];
if (!isset($formSubmitted)) { ?>
<form method="post" enctype="form/multipart" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="formSubmitted" id="formSubmitted" type="hidden" value="1" />
...
</form>
<?php }
else {
// show the graph
}
?>
答案 1 :(得分:1)
在您的文件中,您需要具有以下内容:
<?php if ($someConditionalForTheForm) { ?>
<form>....</form>
<?php } else { ?>
<script id="source" language="javascript" type="text/javascript">
$.plot($("#test"), [ [[0, 0], [1, 1]] ], { yaxis: { max: 1 } });
</script>
<?php } ?>
答案 2 :(得分:0)
if (isset($_GET['your_form_parameter'])) {
also_output_the_JS_graph;
}
这样,表单将始终显示,图表仅在提交表单时显示。
答案 3 :(得分:0)
.js(需要jquery)
$(document).ready(function(){
$('#myformsubmit').click(function(){
$.ajax({
type: "GET",
url: "/your_data_processing_file.php",
data: "",
success: function(result){
$("#graph").html(result);
/*
result is whatever you get from your script that handles
your submited data
*/
}
});
});
});
html的
<form id="myform">.....</form>
<div id="graph"><!-- here i want my result appear after submit
without reloading the page, i'm so 1337 --></div>
为了更加酷,您可以返回json数据并通过图表js处理。