简体   繁体   English

设计决策-Javascript数组或http处理程序

[英]Design Decision - Javascript array or http handler

I'm building a Web Page that allows the user to pick a color and size. 我正在构建一个允许用户选择颜色和大小的网页。 Once they have these selected I need to perform a lookup to see if inventory exists or not and update some UI elements based on this. 一旦选择了它们,我需要执行查找以查看库存是否存在,并基于此更新一些UI元素。

I was thinking that putting all the single product data into multidimensional JavaScript array (there is only 10-50 records for any page instance) and writing some client side routines around that, would be the way to go for two reasons. 我当时想将所有单一产品数据放入多维JavaScript数组(任何页面实例只有10至50条记录)并围绕它编写一些客户端例程,这是出于两个原因的方法。 One because it keeps the UI fast and two it minimizes callbacks to the server. 一是因为它可以使用户界面保持快速,二是可以最大程度地减少对服务器的回调。 What i'm worried about with this solution is code smell. 我担心这种解决方案的是代码气味。

As an alternative i'm thinking about using a more AJAX purist approach of using HTTP handlers and JSON, or perhaps a hybrid with a bit of both. 作为一种替代方案,我正在考虑使用一种使用HTTP处理程序和JSON的更AJAX纯粹方法,或者可能是两者结合使用。 My question is what are your thoughts as to the best solution to this problem using the ASP.Net 2.0 stack? 我的问题是,您对使用ASP.Net 2.0堆栈解决此问题的最佳解决方案有何想法?

[Edit] [编辑]

I also should mention that this page will be running in a SharePoint environment. 我还应该提到此页面将在SharePoint环境中运行。

Assuming the data is static, I would vote option #1. 假设数据是静态的,我将投票选择选项1。 Storing and retrieving data elements in a JavaScript array is relatively foolproof and entirely within your control. 在JavaScript数组中存储和检索数据元素相对简单,并且完全在您的控件之内。 Calling back to the server introduces a lot of possible failure points. 调用服务器会引入很多可能的故障点。 Besides, I think keeping the data in-memory within the page will require less code overall and be more readable to anyone with a more than rudimentary understanding of JavaScript. 此外,我认为将数据存储在页面内将需要较少的整体代码,并且对JavaScript的基本了解将更易于理解。

i'm against Ajax for such tasks, and vote (and implemented) the first option. 我反对Ajax执行此类任务,并投票(并实施)第一个选择。

As far as I understand, you won't create Code smells if the JS part is being written by your server-side. 据我了解,如果JS部分是由服务器端编写的,则不会创建Code气味

From a user point-of-view, Ajax is an experience-killer for wireless browsing, since any little glitch or mis-service will fail or simply lengthen the interaction by factors of 20(!). 从用户的角度来看,Ajax是无线浏览的体验杀手,因为任何小故障或错误服务都将失败或仅将交互延长20倍!

I've implemented even more records than yours in my site, and the users love it. 在我的网站上,我实现的记录甚至超过您的记录,并且用户喜欢它。 Since some of my users use internet-caffee, or dubious hotel wifi, it wouldn't work otherwise. 由于我的一些用户使用可上网的咖啡厅或可疑的酒店wifi,因此无法正常使用。

Besides, Ajax makes your server-vs-client interaction code much more complex, IMO, which is the trickiest part in web programming. 此外,Ajax使您的服务器与客户之间的交互代码更加复杂,即IMO,这是Web编程中最棘手的部分。

I would go with your second option by far. 到目前为止,我会选择您的第二个选择。 As long as the AJAX call isn't performing a long running process for this case, it should be pretty fast. 只要在这种情况下AJAX调用不会执行长时间运行的过程,它就应该非常快。

The application I work on does lots with AJAX and HttpHandler, and our calls execute fast. 我处理的应用程序在AJAX和HttpHandler上有很多功能,我们的调用执行速度很快。 Just ensure you are minimizing the size of your JSON returned in the response. 只需确保最小化响应中返回的JSON大小即可。

Go with your second option. 选择第二个选项。 If there are that few items involved, the AJAX call should perform fairly well. 如果涉及的项目很少,则AJAX调用应该表现良好。 You'll keep your code off the client side, hopefully prevent any browser based issues that the client side scripting might have caused, and have a cleaner application. 您将使代码远离客户端,希望避免客户端脚本可能引起的任何基于浏览器的问题,并拥有更干净的应用程序。

EDIT 编辑

Also consider that client side script can be modified by the user. 还应考虑用户可以修改客户端脚本。 If there's no other validation occuring to the user's selection, this could allow them to configure a product that is out of stock. 如果没有其他验证发生在用户的选择中,则这可能允许他们配置断货的产品。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM