使用 php 或 javascript 在 textarea 中的行更改时在数据库中插入数据。没有任何点击或任何提交按钮
Insert data in database when line change in textarea using php or javascript. without any click or any submit buttons
我有一个文本区域。我想当我在 textarea 中写入数据时,当 textarea 中的行发生变化时,数据将插入 table 并且 textarea 自动为空白。
您可以使用 jQuery。选择一种方法。 不要使用这两种方法。
通过表单提交 - 它会刷新页面
<script>
$("#textarea-id").keyup(function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
$('#form-id').submit();
}
});
</script>
通过Ajax提交-不会刷新页面
<script>
$("#textarea-id").keyup(function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
$.ajax({
url: 'insertrecords.php',
type: 'GET',
data: 'name=paul',
success: function (data) {
//called when successful
$('#ajaxphp-results').html(data);
},
error: function (e) {
//called when there is an error
//console.log(e.message);
}
});
}
});
</script>
我有一个文本区域。我想当我在 textarea 中写入数据时,当 textarea 中的行发生变化时,数据将插入 table 并且 textarea 自动为空白。
您可以使用 jQuery。选择一种方法。 不要使用这两种方法。
通过表单提交 - 它会刷新页面
<script>
$("#textarea-id").keyup(function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
$('#form-id').submit();
}
});
</script>
通过Ajax提交-不会刷新页面
<script>
$("#textarea-id").keyup(function (e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
$.ajax({
url: 'insertrecords.php',
type: 'GET',
data: 'name=paul',
success: function (data) {
//called when successful
$('#ajaxphp-results').html(data);
},
error: function (e) {
//called when there is an error
//console.log(e.message);
}
});
}
});
</script>