簡體   English   中英

使用Java腳本將表單數據發送到服務器並將其存儲在服務器中

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

我有一個表單頁面,我想將表單詳細信息提交到我的服務器,並將詳細信息存儲在服務器中。

我需要一個腳本來將客戶端的請求發送到服務器,並且我想到了使用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();
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM