tags:

views:

85

answers:

3

Am trying to make a get request from javascript, with a function called geturl. So if i prepare my querys and add it in to an array, and looping throw that executes just one request. how can do that without a for loop? perhaps doing something with the array?

for (var i=0; i<urls.length; i++)
        {
           url[i] = urls[i].value;
        }
geturl(url);
+1  A: 

if you are using a javascript framework you could do something along the lines of:

var collection;
$(urls).each(function(v){//add to collection});
geturl(collection);

jQuery each documentation

gum411
This would work, but I am failing to understand he even wants to get rid of the for loop. The $.each() method uses a for loop internally anyway.
Graza
I dont quite understand why the loop has to go either but its the only interpretation i could come up with.
gum411
+1  A: 

You could use a framework such as prototype or jQuery that give you an each() method to use on the array, but internally it would likely just use a for loop anyway, so there's not really much point to it.

Alternatively, if this is because you are using the for loop all over the place and want to have reusable code instead, why not attach a buildUrl method to your urls object (which loops internally, and returns your url array)

Or modify geturl() so it looks at the .value property of the argument rather than expecting each element of url[] to be a string, then pass urls[] in to geturl (eg geturl(urls); rather than passing in the array of string url

Graza
+1  A: 

A total stab in the dark, if the question is

Why does geturl only get called once?

Then the answer could be:-

for (var i=0; i<urls.length; i++)
{
  url[i] = urls[i].value;
  geturl(url[i]);
}

However it is not apparent!

Rippo
I tryed that several times it aborts and executes just one request
streetparade
That would suggests that your problem lies in the implementation of geturl. Post the code!
gum411