简体   繁体   English

存储/获取信息客户端的最佳方式

[英]Best way to store/get information client side

I have a ASP web application that uses listboxes. 我有一个使用列表框的ASP Web应用程序。 My dilemma is that changes in items selection on the listboxes will happen fast and frequently, so doing a postback to get the information that I need would end up being very slow on the client side. 我的困境是列表框中项目选择的更改将快速且频繁地发生,因此进行回发以获取我需要的信息将最终在客户端变得非常慢。

My question is: What is the best way to store data on the client side? 我的问题是:在客户端存储数据的最佳方法是什么? or should I just use something like Postback, or ajax? 或者我应该使用像Postback或ajax这样的东西?

The information that needs to be stored could be in a single string for each item that I can split, but there will need to be the information for all of the items in the Listbox and the number of items in the Listbox is unknown. 对于我可以拆分的每个项目,需要存储的信息可以是单个字符串,但是需要包含列表框中所有项目的信息,并且列表框中的项目数量是未知的。

Please let me know what you think would be the best place to have the information. 请告诉我您认为最适合获取信息的地方。

It really depends on how far you want to take things. 这真的取决于你想要走多远。 Postback will be quick to implement but may prove to be awkward and slow. 回发将很快实施,但可能证明是尴尬和缓慢。 Using ajax in one way or another will speed things up considerably and there are many ways this can be used. 以某种方式使用ajax会大大加快速度,并且有很多方法可以使用它。 The extent of which will be determined by how much time you want to spend developing it vs the benefit to the user / frequency of use. 其程度取决于您希望花费多少时间来开发它与使用者的利益/使用频率。

As a specific answer I would suggest AJAXing the data in, but whether you do this every time you need it or once on load, would depend on application/context. 作为一个具体的答案,我建议使用AJAXing数据,但无论你是在每次需要时还是在加载时都这样做,都将取决于应用程序/上下文。

As g.foley wrote it is context specific and can't be answered without getting more details. 正如g.foley所写,它是特定于上下文的,如果没有获得更多细节,就无法回答。
I can say I used to hold a JavaScript object that I sent only on submit of a form, maybe this approach will suite you. 我可以说我曾经持有一个我只在提交表单时发送的JavaScript对象,也许这种方法会让你感到满意。

From the sub-context of the question, I'm going to make a guess that you don't really need information from the server when selection on listboxes changes? 从问题的子上下文中,我将猜测当列表框上的选择发生变化时,您真的不需要来自服务器的信息吗? If I'm right, then you can store the information in the javascript variables and then right before the browser navigates to another page/closes (onBeforeUnload) post the data back to the server through AJAX. 如果我是对的,那么你可以将信息存储在javascript变量中,然后在浏览器导航到另一个页面/关闭(onBeforeUnload)之前将数据通过AJAX发布回服务器。 This way you will cut back on the constant communication with the server. 这样,您将减少与服务器的持续通信。 If you do end using this method, be aware that Chrome really doesn't like Async AJAX calls on unload or beforeUnload. 如果您最终使用此方法,请注意Chrome确实不喜欢卸载或beforeUnload上的Async AJAX调用。 You will need to make your call synchronous. 您需要使您的呼叫同步。 IE also doesn't like it, but with a different result. IE也不喜欢它,但结果不同。 You might actually lose a connection to the server, so when the next page loads from your website instead of using 4/6 connections simultaneously, you will only have 3/5 available. 您可能实际上失去了与服务器的连接,因此当您的网站加载下一页而不是同时使用4/6连接时,您将只有3/5可用。

If I guessed wrong, then your best bet is AJAX call to the server when selection changes. 如果我猜错了,那么最好的选择是在选择更改时对服务器进行AJAX调用。 That would be the fastest way to get information (other than WebSockets). 这将是获取信息的最快方式(WebSockets除外)。

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

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