简体   繁体   English

在ASP.NET MVC2的客户端缓存Ajax结果

[英]Caching ajax result on client side in asp.net mvc2

I want to do something like 我想做类似的事情

替代文字

This is screenshot of google transliterator that can be found here . 这是google transliterator的屏幕截图,可以在这里找到。 In this application user writes in Roman script and when he/she presses space an ajax request goes to server bringing back list of words. 在此应用程序中,用户使用罗马脚本书写,当他/她按下空格时,Ajax请求将发送到服务器,以带回单词列表。 Roman word is then replaced by word top in the result list (Urdu result list in my case). 然后,将罗马字替换为结果列表中的单词top(在我的情况下为Urdu结果列表)。 Now when I continue typing and after sometime i come back and see that a word is not like I intended to write. 现在,当我继续打字时,过了一段时间,我回来了,发现单词不像我打算写的那样。

I click on that word and a context menu would open like shown in the figure, but the important thing is that this time no ajax request goes to the server rather Google picks the result somewhere stored in client area (browser). 我单击该单词,然后将打开一个上下文菜单,如图所示,但重要的是这次没有任何ajax请求发送到服务器,而是Google选择了存储在客户区(浏览器)中的结果。 My question is how can I cache ajax result on client side and second thing is how I can associate each result with each word in text area or rich text box using a context menu or similar interface. 我的问题是如何在客户端缓存Ajax结果,第二件事是如何使用上下文菜单或类似界面将每个结果与文本区域或富文本框中的每个单词相关联。

I want to accomplish similar functionality in asp.net mvc2. 我想在asp.net mvc2中完成类似的功能。

Just store the result of your ajax call in a javascript variable - you can access it later on: 只需将ajax调用的结果存储在javascript变量中-您以后可以访问它:

var dictionary = new Object();
var input = 'hello';

$.ajax({
  url: url,
  dataType: 'json',
  data: data,  // <-- you send your input to server here
  success: function(response) {
    dictionary[input] = response;
  }
});

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

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