简体   繁体   English

在同一页面中使用多个Ajax表单

[英]Working with multiple ajax forms in same page

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. 经过这个问题的建议后,页面中存在多种形式-通过Ajax加载错误消息,我试图在同一页面中处理多种形式。 I am trying to append error messages in to the respective input div classes. 我试图将错误消息附加到相应的输入div类中。 I don't want to have different form ids because i need to have single id in the jquery then. 我不想有不同的表单ID,因为那时我需要在jquery中具有单个ID。 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>

and the jQuery part is jQuery部分是

$('.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>'); 
     }
   } 
  });
});

however the ajax part is working but the error messages do not load in the div tags as defined in the jQuery 'div.' + divclass 但是,ajax部分正在运行,但错误消息未按照jQuery'div 'div.' + divclass定义加载到div标签中'div.' + divclass 'div.' + divclass . 'div.' + divclass Any help would be appreciated 任何帮助,将不胜感激

像这样?

postform.find('.message').append('<span>' + message + '</span>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM