views:

30

answers:

1

Hello everyone,

i want to do something like alt text

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 words. 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. any help and suggestion is highly appreciated
regards

+1  A: 

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;
  }
});
Jakub Konecki
thanks for reply. i just want to create a dictionary thing say in my first call i send parameter word = "hello" dictionary should contain ajax result indexed by word "hello" and second time i need this result i would check dictionary if result for "hello" is present in dictionary otherwise i will go and fetch it from server. i wonder how can i create this dictionary thing in js (jquery)
Muhammad Adeel Zahid
In JS every object is a dictionary ;-) Use var dic = new Object(); dic['hello'] = myArray; dic['hello2'] = otherArray; var helloAnswers = dic['hello']; (Just edited my answer)
Jakub Konecki
hmm that should work +1. lemme try it after weekend. have good time
Muhammad Adeel Zahid