开发者

Caching ajax result on client side in asp.net mvc2

I want to do something like

Caching ajax result on client side in asp.net mvc2

This is screenshot of google transliterator that can be found here. In this application user writes in Roman script and when he/she presses space an ajax request goes to server bringing back list of w开发者_Python百科ords. Roman word is then replaced by word top in the result list (Urdu result list in my case). 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). 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.

I want to accomplish similar functionality in asp.net mvc2.


Just store the result of your ajax call in a javascript variable - you can access it later on:

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;
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜