多阿贾克斯形式的同一页面上工作面上、形式、工作、多阿贾克斯

2023-09-10 20:25:33 作者:心弦perpLexIty

这是这个问题的Multiple通过AJAX 加载错误信息 - 形式在页面 我努力工作,多形式的同一页面。 我试图附加到相应的输入格类的错误消息。 我不希望有不同的形式的ID,因为我需要有一个ID在jQuery的话。 我有形式,如

After a suggestion from this question Multiple forms in in a page - load error messages via ajax I am trying to work multiple forms in same page. I am trying to append error messages in to the respective input div classes. I don't want to have different form ids because i need to have single id in the jquery then. I have forms like

<form class="myform" name="myform">
<div class="name">
<input type="text" name="name" />
</div>
<div class="message">
<input type="text" name="message" />
</div>
<input type="submit" name="submit" />
</form>

<!-- second form -->
<form class="myform" name="myform">
<div class="name">
<input type="text" name="age" />
</div>
<div class="message">
<input type="text" name="gender" />
</div>
<input type="submit" name="submit" />
</form>

和jQuery的部分是

and the jQuery part is

$('.myform').on('submit', function(event) { 
  postform = $(this); 
  event.preventDefault(); 
  $(this).ajaxSubmit({ 
   url: 'process.php', 
   type: 'post', 
   dataType: 'json', 
   success: function( response ){ 
     $.each(response, function(index, element){
       var msgdiv = postform.children('div.' + divclass).append('<span>'+message+'</span>'); 
     }
   } 
  });
});

不过阿贾克斯部分工作,但在div标签作为jQuery的定义的错误消息不加载格。 + divclass 。任何帮助将是AP preciated

however the ajax part is working but the error messages do not load in the div tags as defined in the jQuery 'div.' + divclass. Any help would be appreciated

推荐答案

喜欢这个?

postform.find('.message').append('<span>' + message + '</span>');
 
精彩推荐
图片推荐