使用Java脚本向服务器发送表单数据并将其存储在服务器中

Send Form data to server and store it in the server using Java script

本文关键字:服务器 存储 数据 表单 脚本 Java 使用      更新时间:2023-09-26

我有一个表单页面,我想提交表单的详细信息到我的服务器,并存储服务器内的详细信息。

我需要一个脚本发送客户端的请求到服务器,我想到使用JavaScript。

我在搜索时遇到了XMLHttpRequest。

谁能告诉我正确的方向?

JavaScript是一种客户端脚本语言,它不能在服务器上存储任何东西,因为您需要服务器端脚本语言。

绘制表单并向用户询问数据的第一部分很简单,可以在HTML中完成,如果您想让它看起来漂亮的话,还可以使用一些jQuery。服务器端将需要一个PHP/ASP脚本来存储或发送提交的数据。

的例子:HTML (form.html):

<form method="POST" action="store.php">
Enter Your Name: <input type="text" name="fullname" />
</form>
PHP (store.php):

<?php
 foreach($_POST as $name=>$value)
 {
    $contents .= "$name = $value" . "'n";
 }
 // save locally in cache folder
 $fd = fopen("cache/filename.txt", "w");
 fwrite($fd, $contents);
 fclose($fd);
 // mail me the submitted data
 @mail("me@there.com", "some subject", $contents);
 // die in piece
 die();
?>