我希望访问者复制/粘贴或写入文本区域字段的数据被保存到Web服务器中的txt文件中,但是我似乎无法弄清楚。
到目前为止,我有这个html:
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label for="data" class="col-sm-2 control-label">The Data</label>
<div class="col-sm-10">
<textarea id="data" onChange="saveToTxt(this); class="form-control"></textarea>
</div>
</div>
脚本:
<script>
function saveToTxt(fld) {
const textAreaValue = fld.value;
// then use textArea variable as container of textarea-content
// and then treat it as you want.
}
</script>
用于写入txt文件的php文件:
<?php
$handle = fopen("data.txt", "a");
foreach($_POST as $variable => $value) {
fwrite($handle, $variable);
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
在访问者不必按任何按钮的情况下,我似乎无法弄清楚如何从表单中调用php。
有没有建议?
编辑:我也尝试过:
<script>
function editPhrase() {
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile("filename.txt", True);
var phraseChange = document.getElementById('data');
s.writeline("Phrase :" + phraseChange);
s.writeline("-----------------------------");
s.Close();
}
</script>
答案 0 :(得分:0)
尝试一下
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GameActivity">
<com.game.project.GameMap
android:id="@+id/gameMapView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
PHP
`$('#data').on('keyup', function() {
var data = $('#data').val();
$.ajax({
url: './process.php',
method: 'POST',
data: {data: data}
})
});`