gpt4 book ai didi

php - 提交表单并在同一页面上显示结果而无需刷新

转载 作者:行者123 更新时间:2023-11-29 01:11:40 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to have user submit text in form and AJAX it to enter to db and show up on same page?

我想做的事情:

index.html -> 表单提交到 some.php -> 处理数据(来自 index.html)并将数据发送到 server.php -> 将结果返回到 index.html div。

我读过 ajax、jQuery,我在这个网站上看到了数百个问题,但我还是想不通。

index.html:

<form action="some.php"  method="post">
Start date: <br/> <input name="idate" id="firstdate" type="text" /><br />
End date: <br /> <input name="fdate" id="seconddate" type="text" /><br />
<br />
<input type="button" id="searchForm" onclick="SubmitForm();" value="Send" />
</form>

一些.php:

<?php
session_start();
$_SESSION['data1'] = $_POST['firstdate'];
$_SESSION['data2'] = $_POST['seconddate'];
?>

function drawChart() {
var jsonData = $.ajax({
url: "server.php",
dataType: "json",
async: false
}).responseText;

var obj = jQuery.parseJSON(jsonData);
var data = google.visualization.arrayToDataTable(obj);

(...)

服务器.php:

$SQLString = "SELECT    
count(score) as counts,
DATE(date),
SUM(CASE WHEN gender = 1 then 1 ELSE 0 END) Male,
SUM(CASE WHEN gender = 2 then 1 ELSE 0 END) Female,
AVG(age) as age, score
FROM persons
WHERE date > '".$_SESSION['date1']."' AND date < '".$_SESSION['date2']."'
GROUP BY DATE(date)
ORDER BY DATE(date) asc";

(...)
$data[0] = array('day','counts','Male','Female','Age','Score');
(...)
echo json_encode($data);

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com