Stripes 和 Ajax - 如何使用 AJAX 将数据发送到服务器并用数据刷新表
我在网上浏览如何将 AJAX 与 Stripes 结合使用,并找到了这个。然而,文档解释了使用原型框架作为客户端脚本。不是 JavaScript。但我想用javascript代替。
我认为这个块使用了原型库。
<script type="text/javascript"
src="${pageContext.request.contextPath}/ajax/prototype.js"></script>
<script type="text/javascript" xml:space="preserve">
/* ... */
function invoke(form, event, container) {
if (!form.onsubmit) { form.onsubmit = function() { return false } };
var params = Form.serialize(form, {submit:event});
new Ajax.Updater(container, form.action, {method:'post', parameters:params});
}
</script>
我怎样才能将其更改为javascript?或者我误解了什么。 我的主要目标是,当用户单击按钮时,我想将该数据发送到服务器并将其显示在表格上,而不刷新整个页面。我有一个 ActionBean 来保存数据。
谢谢。
I was surfing the web how to use AJAX with Stripes and found this. However the documentation explains using Prototype framework as a client side script. Not Javascript. But I want to use javascript instead.
I think this block uses Prototype library.
<script type="text/javascript"
src="${pageContext.request.contextPath}/ajax/prototype.js"></script>
<script type="text/javascript" xml:space="preserve">
/* ... */
function invoke(form, event, container) {
if (!form.onsubmit) { form.onsubmit = function() { return false } };
var params = Form.serialize(form, {submit:event});
new Ajax.Updater(container, form.action, {method:'post', parameters:params});
}
</script>
How can I change it to javascript? Or did I misunderstood something.
My main aim is when a user clicks a button I want to send that data to the server and display it on a table without refreshing the whole page. I have an ActionBean who will save the data.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不打算导入库(我建议这样做,因为此代码对于非 JS 程序员来说可能有点繁重),那么您需要自己构建 XMLHttpRequest 对象。 MDN 上有一个很好的指南,涵盖了基础知识,但通常是这样做的so:
如您所见,这不是最简单的代码。我强烈建议您仔细阅读有关该主题的 MDN 页面,因为它会对您有所帮助理解上面的代码。它可以帮助您执行更多操作,例如随请求一起发送数据。并不是说这里的序列化和提交表单比我上面的示例更多。如果您想提交表格,您需要确保彻底阅读该文章。
我为什么推荐像 Prototype 或 jQuery 这样的 JS 库,因为它们使所有这些(以及更多)变得更加简单。
If you are not going to import a library (which I would recommend, because this code can be a little heavy for non-JS programmers) then you'll need to build the XMLHttpRequest object yourself. There is a good guide over at MDN that covers the basics, but it is generally done like so:
As you can see, it isn't the easiest code. I'd highly recommend reading through the MDN page on the subject, because it will help you understand the code above. It can help you do more things with this, like send data along with your request. Not that serializing and submitting a form here is more than my example above does. If you want to submit a form, you'll want to make sure to read through the article thoroughly.
Why I recommend a JS library like Prototype or jQuery is because they make all of this (and more) a lot simpler.