简体   繁体   English

如何在模式框中进行服务器端Ajax验证

[英]How to do a server-side Ajax validation in a modal box

I currently have an app that is using a twitter bootstrap modal box. 我目前有一个使用Twitter Bootstrap模式框的应用程序。 The div that the modal is displaying is getting loaded with JQuery from /users/new action. 模态显示的div从/ users / new操作中被JQuery加载。 Everything works great if the user enters valid data in the modal box submitted but if the data sent to params does not pass validation the controller redirects back to the new action but this time outside of the modal box and the page that user was previously on is gone, which sort of defeats the purpose of having the modal box to begin with. 如果用户在提交的模式框中输入有效数据,则一切工作都很好,但是如果发送给params的数据未通过验证,则控制器将重定向回新操作,但是这次不在模式框中,并且用户之前所在的页面是消失了,这破坏了使用模态盒的目的。

I have looked at Live-Validation and other javascript based client-side validations. 我看过Live-Validation和其他基于JavaScript的客户端验证。 These are an option but I would much prefer being able to use my existing validations in the users model for consistency's sake. 这些是一个选项,但是为了保持一致性,我更希望能够在用户模型中使用现有的验证。 I there a good way to make the modal box persist while the form is being submitted and to make the controller reload the page within the modal with the error_messages? 我有一个很好的方法可以使模式框在提交表单时保持不变,并让控制器使用error_messages重新加载模式内的页面?

Thanks 谢谢

Are the error_messages loaded into the modal using javascript? 是否使用javascript将error_messages加载到模式中? If so, you could have the page check to see if there are error_messages on load, then pop open the modal box if there are any. 如果是这样,您可以让页面检查以查看是否加载了error_messages,然后如果有的话弹出模式框。 This won't save any input from the modal, but it will pop it open. 这不会保存模态中的任何输入,但是会弹出它。

Alternatively, you could implement some light client side validation on top of your current model. 或者,您可以在当前模型的基础上实施一些轻客户端验证。 However, how light it would be is dependent on how picky your model is regarding its input. 但是,灯光的强度取决于模型对输入的挑剔程度。 If it's very specific what it will accept/reject, it would be much harder to verify consistency, and having something get through client-side validation only to bounce back and say it was invalid isn't always pretty. 如果要接受/拒绝的内容非常具体,则要验证一致性会困难得多,并且让某些内容通过客户端验证只是反弹然后说无效是不总是很漂亮的。

暂无
暂无

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

相关问题 如何使用JQuery / Ajax(和Rails)执行复杂的服务器端表单验证? - How do I perform complex, server-side form validation with JQuery/Ajax (and Rails)? 如何使用Jqgrid进行服务器端验证? - How to do server-side validation using Jqgrid? 如何从引导程序模式中清除服务器端MVC模型验证错误? - How can I clear the server-side MVC model validation errors from a bootstrap modal? 使用jQuery ajax将3个文本框值发送到服务器端方法 - Send 3 text box values to a server-side method with jQuery ajax jQuery ajax发布请求的MVC服务器端验证 - mvc server-side validation for jquery ajax post request 帮助jQuery Ajax发布和服务器端验证消息 - Help with jquery ajax posting and server-side validation messages 如果服务器端验证失败,则MVC AJAX返回视图 - MVC AJAX Return View if server-side validation fails 在MVC5中是否有任何“内置”方式可以进行特定于字段的服务器端AJAX验证? 如果没有,有没有可以帮助您的助手? - Is there any “built-in” way to do field-specific, server-side AJAX validation in MVC5? If not, are there any helpers that can assist with this? 如何使用 ajax 调用将 jQuery 中网格中已删除的行名传递给控制器(服务器端) - How do I pass the deleted row name from a grid in jQuery to controller(server-side) with ajax call 如何在AngularJS中实现服务器端搜索框 - How to implement server-side search box in AngularJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM