Php Ajax响应仅允许字段中的数据(如果为true)

Php Ajax响应仅允许字段中的数据(如果为true),php,ajax,Php,Ajax,我需要有一个字段,将不允许数据输入,如果它返回一个消息“假”。字段“ponumber”检查DB,如果该记录已经存在,我不希望它允许用户使用该特定PO编号。基本上,如果他们离开字段并显示消息,它会将其清空。除了现在允许基于checkponumberajaxphp文件的假返回进行输入外,该脚本工作正常 $(document).ready(function () { var validateponumber = $('#validateponumbe

我需要有一个字段,将不允许数据输入,如果它返回一个消息“假”。字段“ponumber”检查DB,如果该记录已经存在,我不希望它允许用户使用该特定PO编号。基本上,如果他们离开字段并显示消息,它会将其清空。除了现在允许基于checkponumberajaxphp文件的假返回进行输入外,该脚本工作正常

            $(document).ready(function () {
              var validateponumber = $('#validateponumber');
              $('#ponumber').keyup(function () {
                var t = this; 
                if (this.value != this.lastValue) {
                  if (this.timer) clearTimeout(this.timer);
                  validateponumber.removeClass('error').html('<img src="/images/ajax-loader.gif" height="16" width="16" /> checking availability...');

                  this.timer = setTimeout(function () {
                    $.ajax({
                      url: 'includes/checkponumberajax.php',
                      data: 'action=check_ponumber&ponumber=' + t.value,
                      dataType: 'json',
                      type: 'post',
                      success: function (j) { 
                        validateponumber.html(j.msg);
                      }
                    });
                  }, 200);
                  this.lastValue = this.value;
                }
              });
            });

<input type="text" name="ponumber" value="<?=@$_REQUEST['ponumber']?>" id="ponumber" />
编辑:解决了

最后,我感谢@bourch使用了这个函数,一旦达到匹配false的值,它就会将字段清空

if(j.ok != true){$("#ponumber").attr("value", "");}
试试这个:

if(j.ok != true){$("#ponumber").attr("disabled", "disabled");
}

关闭,但一旦您输入一个存在的值,它就会禁用该字段,并且我无法再访问它。LOL。我将“disabled”、“disabled”更改为“value”、“,当达到false时,它会将该值清空。我用答案更新了我原来的问题。谢谢
if(j.ok != true){$("#ponumber").attr("disabled", "disabled");
}