weixin_33721344 2016-06-13 09:52 采纳率: 0%
浏览 17

Ajax提交某些字段

I'm new to Jquery ajax, and I'm trying to submit certain field only for checking instead of submitting the whole form. Here I have made a function for checking the username whether is it available, and it works fine, but I doesn't want it to submit the whole form when doing the checking.

Here is my script:

<form id="userCheck">
<input type="text" class="register_field" name="fr_username" id="fr_username" />
<input type="text" class="register_field" name="fr_password" id="fr_password" />
<input type="text" class="register_field" name="fr_password1" id="fr_password1" />
</form>

<script>
$.validator.addMethod("duplicateCheck", function(value, element) {
            $.ajax({
        type: 'POST',
        url: '../a/checkDuplicate',
        data: $("#userCheck").serialize(),
        dataType: 'json'
    }).success(function(data){
        if(data.status == '1'){
            console.log('Available!');
        }
        else {
            console.log('not available');
            $('#fr_dupChkU_msg').html('');
        }
    });
        });
</script>
  • 写回答

1条回答 默认 最新

  • local-host 2016-06-13 10:04
    关注

    In short, that is how you get a value of an input field with jQuery:

    <script type="text/javascript">
      var username = $('#fr_username').val();
    
      $.validator.addMethod('duplicateCheck', function(value, element) {
                $.ajax({
            type: 'POST',
            url: '../a/checkDuplicate',
            data: {username: username},
        }).success(function(data){
            if(data.status == '1'){
                console.log('Available!');
            }
            else {
                console.log('not available');
                $('#fr_dupChkU_msg').html('');
            }
        });
            });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: