views:

43

answers:

1

Hi everybody...

I have already asked a question but I wanted to ask it in another way with another question. Is that possible call a method 10 times in asynchronous mode without specifying a return value. I am doing everything in a single page. I do not need to visit any other page. I have got a set of operation, each operation should wait for the previous one.

like this:

$.get('myhtmlpage.html', function(){

  myCallBack(param1, param2);

});

or like this:

  function translate(i) {
     google.language.translate(testua, languages[i], languages[i+1], function(result) {
    if (result.translation) {
      text = result.translation;
      f.textarea1.value = text;
      if (i < translationNumber) { translate(i++); }
    }
     }
  }

I believe these are telling me something but I need to see a sample..

http://api.jquery.com/jQuery.ajax/
http://docs.jquery.com/How_jQuery_Works#Callback_and_Functions

or suggest me sth please.

A sample code would be great!

thanks.. regards..

A: 

I think you may be misunderstanding how JavaScript works. In JavaScript you only have one thread, which means that you can't call any functions asynchronously execpt when you do AJAX-style calls.

The short answer is, you can't call methods asynchronously.

Horatio Alderaan
maybe my explanation is wrong. I just need to call a function for each element of an array and I want them to wait for each other.for example, you have got an array which count from 1 to 10. 2 will wait for 1 , 3 will wait for 2 and so forth. However, the cost of each process (each element of my array) is much more costly in terms of time, a few seconds for each maybe more.That's why I need this. Now can you help me over this explanation?
Ozlem