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

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

本文介绍了使用Java脚本将表单数据发送到服务器并存储在服务器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a form page and I would like to submit the form details to my server, and store the details within the server.

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

I need a script to send the client's request to the server and I thought of using JavaScript.

我在搜索时遇到了 XMLHttpRequest.

I came across XMLHttpRequest while searching.

有人能指出我正确的方向吗?

Could anyone please point me in the right direction?

推荐答案

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

JavaScript is a client-side scripting language, it can not store anything on your server as you will need a server-side scripting language.

绘制表单和询问用户数据的第一部分很简单,可以在 HTML 中完成,如果您希望它好看,还可以使用一些 jQuery.服务器端将需要一个 PHP/ASP 脚本来存储或发送提交的数据.

The first part of drawing a form and asking the user for the data is easy and can be done in HTML, and some jQuery if you would like it nice looking. The server-side will require a PHP/ASP script that will store or send the submitted data.

示例:

HTML (form.html):

HTML (form.html):

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

PHP (store.php):

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("[email protected]", "some subject", $contents);

 // die in piece
 die();
?>

这篇关于使用Java脚本将表单数据发送到服务器并存储在服务器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:08