[jQuery] Append inside loop

2009-01-03 Thread vorp

Hi,
can anybody explain me, why this code don't work as I expected ?
Here is:

function get(page){
return $.ajax({
async: false,
type: "GET",
dataType: "json",
url: "some_url.php?page=" + page
}).responseText;
};

function show(data){
data = eval(data);
for(i=0;i<=data.length-1;i++){
$("#results").append(data[i].url + "");
}

}

$("#search").click(function(){
for(page=0;page<=9;page++){
res = get(page);
show(res);
}
return false;
})

In my opinion after click #search it should get portion of data,
display it, get next portion of data and display etc.
In FireFox3 everything is ok, it work fine as I expected, but in
Safari and IE7.0 don't. In these browsers all results are displayed at
once at the end of loop.
Question is, why and how change this code to display portion of data
after get it in Safari and IE7. Maybe bug ?

Regs,
vorp


[jQuery] Re: Ajax request in loop

2008-12-09 Thread vorp

Well ok, I try to explain what I want to do.
At first I forgot to tell, that I have setup all ajax requests in
synchronous mode ( $.ajaxSetup({async: false}) ) so after call my
get_results() function browser should wait for response.
Inside while loop is not only function call, but additionally
displaying get_results() results. This is a part of biggest script and
inside while loop I increase variable "i". Next I call get_results(i).
This function gets google search results  (var "i" is a google page
number) and return to me info about results. So I must use loop,
because I must check on which page number my searching results are.
Now in FF everything is ok. After start, table rows with results are
added at bottom of table, but in Safari when I start script, I see
only rainbow circle (browser "thinking" ;) ) and after few seconds
(minutes) completly table with results is displayed (not step by step
like in FF).

My English is poor. I know that, but I hope you (and others)
understand what I wrote ;)


[jQuery] Ajax request in loop

2008-12-09 Thread vorp

Hi, I try get some results from ajax using while loop, but it doesn't
work in IE7 and Safari.

Here's example code:

function get_results(foo){
return $.ajax({
type: "GET",
url: "some_url.php/"+foo,
dataType: "json"
}).responseText;
};

...
...
var result = 0;
var i = 0;
while(result==0 && i<=49){
 result = get_results(i);
 i++;
}
...

Although it works fine in Firefox and Opera (in firebug I can see
every single request), but in IE and Safari not. Those browsers not
responding after run this code. What's wrong and how can I fix it ?

Regards

ps.sorry for my poor english ;)