如何保持 Ajax Web 表单解决方案干燥

发布于 2024-12-27 07:03:28 字数 473 浏览 6 评论 0原文

目前我们有一个解决方案,那就是Web表单ASP.Net 4.0。我们做了很多事情,例如使用 Web 方法和服务,或者使用标准 Web 表单方式调用它们,或者有时为了减少占用空间,直接使用 jQuery ajax posts 和 gets 调用它们。

我们正在寻求改进我们的工作方式,但我们对目前的解决方案有很大的限制,并且无法完全重写它。

使用 Ajax 更新页面数据、表单,例如拉出“接下来的 20 个”项目并将它们显示在页面上,这是我想要大量简化的流程。

使用模板作为 PURE 和 jQuery 模板是在服务器之间产生快速来回调用的绝佳方法,但会导致 html 的两个副本。 (jQuery 的模板和页面实际第一次渲染中的代码)

我们考虑过可能生成一个空模板,然后总是通过我们发布到服务器的 json 数据填充它,但我觉得事情不是这样的应该完成...

任何人都可以认为我们可以在没有“模板”的两份副本(例如表格的一行)的情况下做到这一点的最佳方法

At the moment we have a solution which is Web forms ASP.Net 4.0. We do a number of things such as using web methods and services either calling them using the standard web forms way or sometimes to reduce the footprint directly calling them with jQuery ajax posts and gets.

We are looking to improve the way we work but we have heavy constricts regarding how the solution is at the moment and not being able to completely rewrite it.

Updating the page using Ajaxs for data, forms and for example pulling "the next 20" items and displaying them on the page it what I would like to heavily stream line.

Using template's due as PURE and jQuery Templates is fantastic way to produce fast calls back and forth between the servers but results in having two copies of the html. (the template for the jQuery and the code in the actual first render of the page)

We have thought about possible producing a empty template and then always populating it via json data we post down to the server but I feel this isn't how things should be done...

can anyone reckoned the best way we can do this without having two copies of our 'template' (e.g. a row of a table)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千紇 2025-01-03 07:03:29

您的意思是您在 asp 中有一个模板,在 javascript 中有相同的模板,但您只想使用 1 个或另一个?

我认为这确实是主观的。根据用例的不同,它总是不同的。话虽这么说,我会通过修改我的视图和模板来做到这一点。我的视图(非 js)只会包含该动态内容的容器。换句话说,我最初不会将内容的动态部分加载到视图中。相反,在页面加载时,我会简单地加载模板和填充它的 json。

如果您考虑一下,这又是 2 个请求,但它让您的生活更轻松。用户还能够更快地看到页面上的内容。

这是真正取决于您在做什么的问题之一。每个解决方案都需要进行权衡分析。

You mean you have a template in asp and the same template in javascript, but you'd rather just have 1 or the other?

I think that is really subjective. It is always different based on use case. That being said I'd do it by modifying my views and templates. My views (non-js) would simply have containers for that dynamic content. In other words I'd never load the dynamic portions of content into the views initially. Rather, on page load I would simply load up the template and the json that fills it in.

If you think about it that's 2 more requests, but it makes your life easier. The user also is able to see something on the page sooner.

This is one of those questions that really depends on what you are doing. There are trade-offs to be analyzed with every solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文