我试图显示远程规则的响应,可能与其他响应位于同一位置。我想要展示的是PHP发送给我的响应。我可以在console.log中轻松显示它,但不知道如何在字段下显示结果
$("#conversionForm").validate({
// Specify the validation rules
ignore:[],
rules: {
"URL[]": {
required: true,
minlength: 3,
pattern: yt,
remote: {url:"checkdescription.php",
type: "post",
beforeSend: function () {
},complete: function (response) {
console.log(response.responseText); //This is what I would like to show
$(this).closest('.form-group').text(response.responseText) // This doesnt work
},
onkeyup: false
}
}
},
messages: {
"URL[]": {
required: "<div style='margin:3.4px 0 0 0'>This field is required</div>",
pattern: "<div style='margin:3.4px 0 0 0'>Enter a valid URL of the type https://www.youtube.com/watch?v=ZDO4I5aT0hg</div>",
minlength:"<div style='margin:3.4px 0 0 0'>Enter a valid URL</div>",
remote:<some invalid message dependent on the php response, too> //help here too
},
success: function(e) {
}
},
});
基本上我想根据php响应自定义错误和成功消息;如果我只能发回真假,那么您认为我应该使用其他什么方法?
谢谢
修改:HTML
<form role="form" action="index.php" method="post" id="conversionForm">
<div id="to-append">
<div class="row" id="input-0">
<div class="col-xs-11 " >
<input type="text" class="form-control" id="youtubeURL-0" name="URL[]" placeholder="Enter your URL here">
</div>
</div>
</div>
<div class="row">
<div class="top-buffer col-xs-12" >
<button type="submit" id="btn-submit" name="submit" >Submit</button>
</div>
</div>
</form>
在此之后,我添加了更多与.row#input-0一样的div与jquery(#input-1,#input-2等)(将它们附加到#to-append)。对于每个输入,远程php返回一个不同的数字,我想在输入字段附近显示该数字。基本上,显示验证远程答案