Send Form data to server and store it in the server using Java script
I have a form page and I would like to submit the form details to my server, and store the details within the server.
I need a script to send the client's request to the server and I thought of using JavaS开发者_如何学JAVAcript.
I came across XMLHttpRequest while searching.
Could anyone please point me in the right direction?
JavaScript is a client-side scripting language, it can not store anything on your server as you will need a server-side scripting language.
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.
Example:
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();
?>
精彩评论