.Net 1.1 中 AJAX 调用的最佳实践

发布于 2024-07-10 11:05:01 字数 537 浏览 2 评论 0原文

嗯,我最新的合同迫使我进入 .Net 1.1 的古董世界。

由于我已经使用 jQuery 和 Rails 有一段时间了,类似 AJAX 的问题解决方案不断出现在我的脑海中,我忍不住把它们写下来。

所以我相当直接的问题是,我需要对记录执行 3 个操作(插入、更新和删除),我可以使用 ASP.Net 控件和 javascript 处理索引和显示。

我使用 jQuery 来处理所有 AJAX 内容。

我想到的方法是引入一个简单的 ASPX 页面,该页面充当这三个操作的控制器,为其提供贫乏的视图并使用字符串连接处理所有返回数据的呈现。 这里有更好的模式可以使用吗? 你是如何将 ajax 融入到 ASP.Net 1.1 中的?

我在 ajaxprojects 上看到了这篇文章,它使用了一些类似的技术,除了他们每个 ajax 操作执行 1 个页面。

Well, my latest contract is forcing me into the antique world of .Net 1.1.

Since I have been using jQuery and Rails for quite a while AJAX like solutions to problem keep on popping into my head and I can't help writing them.

So my fairly straight forward problem is that I have 3 actions I need to perform on a record (insert, update and delete) I can handle index and show using ASP.Net controls and javascript.

I am using jQuery for all my AJAX stuff.

The way I thought of doing this is introducing a simple ASPX page that acts as a controller for these three actions, giving it an anemic view and handling all rendering of return data using string concatenations. Is there a better pattern to use here? How did you hack ajax into ASP.Net 1.1?

I saw this post on ajaxprojects that is using a somewhat similar technique except they are doing 1 page per ajax action.

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

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

发布评论

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

评论(4

做个ˇ局外人 2024-07-17 11:05:01

我们曾经在经典 ASP 中使用 ajax,只需将 XML 消息发布到 ASP 页面,该页面将从请求正文加载 xml。

您可以使用 ASHX 页面(ASP.Net 处理程序)来完成此操作,您不会有任何页面对象的额外开销。 因此,您基本上可以创建一个 Xml 有效负载(或 json 或您想要的任何内容),将其发布到 ashx 页面,该页面有一个方法,该方法将检查请求执行您需要的操作并返回您需要的结果。

We used to use ajax in classic ASP simply by posting XML messages to an ASP page that would load the xml from the request body.

You could do this using an ASHX page (ASP.Net handler) You won't have any of the extra overhead of the page objects. So you can basically create an Xml payload (or json or whatever you want) post it to the ashx page which has a single method which will inspect the request perform what you need and return the results you need.

趴在窗边数星星i 2024-07-17 11:05:01

离开 Web 控制范式越多,使用的视图状态越少,它就会变得越简单,这是令人惊奇但真实的。 然而,ASP.NET 开发使我们免受 HTML、CSS 和 JavaScript 的影响,很少有 ASP.NET 开发人员准备好立即如此直接地处理它们,因此一开始采取中间立场可能是最好的。

好消息是,ASP.NET 1.1 与 jQuery 配合得很好,您可以做任何您想做的事情,从完全避免 Web 控件并仅将原始 HTML 与 jQuery 结合使用,到充分利用 ASP.NET 并加入一点 jQuery例如,在客户端上进行验证,从而避免回发。

采用中间路线的一个例子可能是创建一个普通的数据网格,理想情况下在一个单独的页面上,仅由一个表单元素包围(删除了 runat=server),或者可能只是一个 div 元素,并通过 jQuery 提供它ajax加载方法。

我个人不使用任何 Microsoft Ajax 库。 每次我看到人们在示例中使用它们时,它们似乎只会使 jQuery 已经做得更简单、更快、更好的事情变得复杂。 这个东西很简单,不要在没有充分理由的情况下通过引入不必要的 MS 库和使用庞大的 XML 来使其变得丑陋和缓慢。 我还亲自从所有页面中删除了所有 ViewState,并且还没有发现 ViewState 做了任何对我有用的事情,而直接处理不是更简单、更高效。 事实证明我们从来不需要它,但阿贾克斯敲定了这笔交易。 页面大小的减小和速度的相应提高是一个启示。 更充分地生活在实际的 Web 范式中比生活在有漏洞的 ASP.NET 魔法中要简单得多,也更好。

HTH。

迈克

·P.S. 哇,每个人都开始致力于更简单、更好的 Web 开发:在 ASP.NET WebForms 中控制 HTML

The more you leave the Web Control paradigm, and the less viewstate you use, the simpler it will get, which is amazing but true. However, ASP.NET development shields us from HTML, CSS, and JavaScript, and few ASP.NET devs are prepared to immediately deal with them so directly, so taking the middle ground at first is probably best.

The good news is, ASP.NET 1.1 plays very well with jQuery and you can do anything you want, from avoiding web controls altogether and just using raw HTML with jQuery, to making full use of ASP.NET and sprinkling in just a little jQuery to, say, validate on the client and thereby avoid a postback.

An example of taking a middle route might be to create a normal datagrid, ideally off on a separate page, surrounded by only a form element (with runat=server removed), or perhaps just a div element, and serving it up via the jQuery ajax load method.

I personally do not use any of the Microsoft Ajax libraries. Every time I see people using them in samples, they seem to only complicate that which jQuery already does simpler and faster and better. This stuff is straightforward, don't make it ugly and slow by pulling in unnecessary MS libraries and using bulky XML without some really good reasons. I also personally remove all ViewState from all pages, and haven't yet found a case where ViewState did anything useful for me that wasn't simpler and more efficient just to handle directly. It turns out we never needed it, but Ajax sealed the deal. And the decrease in page size with corresponding increase in speed is a revelation. Living more fully in the actual web paradigm is so much simpler and better than living with leaky ASP.NET magic.

HTH.

Mike

P.S. Wow, everyone is coming on board to simpler, better web development: Controlling HTML in ASP.NET WebForms

划一舟意中人 2024-07-17 11:05:01

继续使用 jquery 开发自己的应用程序并不是一个坏主意,但显然您必须“重新发明轮子”,在现有控件中创建基本的 ajax 支持。 完成该项目的最快方法是追踪支持 .NET 1.1 的 Infragistic 控件的最新版本。

如果他们 2007 年的软件包中仍然有 1.1 版本,我不会感到惊讶,因为它们的兼容性非常好。

Continue rolling your own with jquery isn't a bad idea but obviously you'll have to "reinvent the wheel" creating basic ajax support in existing controls. The fastest way to complete the project would be to track down the last versions of Infragistic controls that support .NET 1.1.

I wouldn't be surprised if they still had 1.1 flavors in their 2007 packages as they are pretty good about compatibility.

北方的巷 2024-07-17 11:05:01

我在 1.1 项目中使用了 AjaxPro 并取得了相当大的成功。 我使用的模型是构建用户控件来表示“视图”,然后在 ajax 请求中动态加载用户控件并调用控件上的 Render() 方法。

当您调用 Render() 时,它会将控件的 HTML 写入文本编写器,然后您可以通过 ajax 调用返回到客户端并插入到占位符 div 中。

I used AjaxPro for my 1.1 projects with quite a lot of success. The model that I used was to build up usercontrols to represent the 'views' then in the ajax requests I'd dynamically load the usercontrol and call the Render() method on the control.

When you call Render() it will write the HTML for your control to a text writer which you can then return to client via your ajax call and insert into a placeholder div.

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