使用ajax清空(val)html字段,然后在数据库中的该字段中输入下一个值


Empty (val) html field with ajax and enter next value in that field from database

我正在开发学生管理系统,所以在我的HTML表单中,我有很多字段,包括以下

  • 学生Id
  • 纸张编号
  • 得分

HTML FORM使用Ajax提交表单数据,因此我希望在提交表单时to empty (val) student id field and fill the student id field with next student id from MySQL以及val Score字段。

我的问题是如何用MySQL中的下一个值填充学生id字段。

如果from不是通过Ajax提交的,我只需要从MySQL数据库中获取并回显下一个值。

以下是我用来提交表单的Ajax代码

<script type="text/javascript">
    $(document).ready(function() {
        $("#keyingForm").submit(function() {
            $("#loading").slideDown();
                 var frm = $('#keyingForm');
                 $.ajax({
                     type: frm.attr('method'),
                     url: 'scoring.php',
                     data: frm.serialize(),
                     success: function (data) {
                         $('#loadData').html(data);
                         $("#loading").slideUp();
               }, error: function(jqXHR, textStatus, errorThrown){
              console.log(" The following error occured: "+ textStatus, errorThrown );
            } });
           return false;
        });
    });     
</script>

学生id字段id为studentid,得分为scoreid字段我希望这是有意义的,因为我不擅长Ajax或JavaScript,谢谢你的帮助

在PHP成功时,尝试加载以下js

<script type="text/javascript">
    //$(document).ready(function() {
        $('#studentid').val(''); $('#x1').val(''); 
        var tav    = $('#studentid').val(),
        strPos     = $('#studentid')[0].selectionStart;
        front      = (tav).substring(0,strPos),
        back       = (tav).substring(strPos,tav.length); 
        $('#studentid').val(front + "<?php echo $newstudentid; ?>" + $(this).text() + '' + back);               
    //});
</script>