页内 Ajax 表单
我目前正在创建一个应用程序,并希望添加 AJAX 功能,但我似乎找不到任何我想要的示例!
我试图将所有内容都保留在一页上。
例如,我的页面左侧已经有一个自动生成的产品列表,该列表通过 JQUERY-->servlet 显示。
现在,如果用户单击某个产品,它会将他们定向到一个 html 页面,其中包含一个提交到 servlet 的表单(我还没有对此进行编码,但我也知道如何进行)。
但我想要的是,当用户单击产品时,表单会加载到页面上指定的 div 中,用户可以在其中填写并提交到 servlet,而无需离开页面。
我最好编码一个 JSP 页面,然后将其拉入主 JSP 页面吗?或者在 jquery 中创建一个表单?
有人能指出我正确的方向吗?
I am currently creating a application and would like to add a AJAX feature, but i cant seem to find any examples of what i want!
Im tryin to keep everything on one page.
So for example, i already have a automatically generated list of products down the left of my page, which are displayed via JQUERY-->servlet.
now if a user clicks on a product it directs them to a html page with a form that submits to the servlet (i haven't coded this, but i know how too).
But what i want is, when a user click the product, the form is loaded into a designated div on the page, in which a user can fill it in and submit to the servlet without leaving the page.
Would i be better of coding a JSP page and thenpulling that into the main JSP page? or creating a form in jquery?
Could anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看一下 jQuery-ui 对话框、验证插件和表单插件。这些应该是您生成基于 ajax 表单并进行验证的出色对话框所需的全部内容。
如果您需要上传文件,我发现 uploadify 插件非常适合提交带有表单数据的文件。
Have a look at the jQuery-ui dialog, the validation plugin and the form plugin. These should be all you need to produce great dialog based ajax forms with validation.
If you need to upload files, I have found that the uploadify plugin is great for submitting files with form data.
考虑到未来,我会让表单成为它自己的 JSP,并通过 jQuery 将其拉入,这将使编辑表单变得更容易,并且下一个开发人员更容易找到。维护用 jQuery(或一般的 JS)构建的表单并不有趣。
With the future in mind I would have the form be its own JSP and pull it in via jQuery, it will make it easier to edit the form and will be easier to find for the next developer. Maintaining forms built in jQuery (or JS in general) is not fun.
我认为您所描述的可以使用模式对话框类型的 jQuery 插件来完成。其中有很多,但您可以查看 jQuery UI 的对话框小部件(链接) 查看基本的。
更好的一个是 Eric Martin 的 simplemodal。您可以在模式中显示表单,然后让用户将模式提交到您的后端服务器。
我更多地处理 .NET 编程,但将这些插件用于模态表单并将它们提交到后端服务。我通常将表单提取到单独的 HTML 页面中,然后动态加载该表单。它使我的 JavaScript 免受标记的影响,并且还允许我更改我的模式模板,而无需真正深入研究我的 JavaScript 文件。
I think what you're describing can be accomplished using a modal dialog type of jQuery plug-in. There are a number of them out there, but you can look at jQuery UI's dialog widget (link) to see a basic one.
A better one is simplemodal from Eric Martin. You can display your form in the modal and then have the user submit the modal to your back-end server.
I deal more with .NET programming, but use these plug-ins for modal forms and submitting them to back-end services. I usually extract the form into a separate HTML page and then load the form in dynamically. It keeps my JavaScript free from markup and also allows me to make changes to my modal template without really digging into my JavaScript files.