我有一个表单页面,我想将表单详细信息提交到我的服务器,并将详细信息存储在服务器中。
我需要一个脚本将客户端的请求发送到服务器,我想使用JavaScript。
我在搜索时遇到了XMLHttpRequest。
有人可以指出我正确的方向吗?
答案 0 :(得分:5)
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();
?>