views:

36

answers:

2
A: 

@patrick, thanks for the suggestion, but that does not resolve the problem. It has something to do with the async call, because if I set async to fase using the primitive $.ajax instead of $.get, I get my portals in the correct order :). But using sync is very bad and very slow, plus the modules themselves rely on async code inside...

Seth
(sorry, this was the only way to respond to your comment)
Seth
@Seth - Please use the comments functionality under your answer for dialog. Thanks. :o)
patrick dw
@Seth - That is because you are using a different user name. If you log in under your original account, you should at least be able to comment on your question. http://stackoverflow.com/users/365546/seth-vargo
patrick dw
@Patrick - "items appended into the same column may not get appended in the same order " - that is my main problem :(. I am trying to make a custom portal where users can customize the layout. If they are appended in the order the requests are received, then I have no way of actually remembering where the user wants his or her module...
Seth
@Seth - I updated my answer (and the live example) so that a numbered `<span>` tag set is created for each request. The result is then placed in the correct span in each column. The `j` variable needed to be passed in, so I modified `addModule` to accept that parameter as well.
patrick dw
@Seth - ...also, if my **updated** answer ends up being the correct solution for you, please remember to confirm by clicking the checkmark next to it. Thanks. :o)
patrick dw
it works now! but i don't have a checkmark... I posted this q before I actually made an account, so how do I get it to show up?
Seth
@Patrick - I can ask the question again and you can copy/paste your code and I'll give you credit for that one if it'll let me...
Seth
@Seth - Just log in using your previous account (see link below). You'll probably have to log out of the current account. It is better to not post the same question again. http://stackoverflow.com/users/365546/seth-vargo
patrick dw
Okay thanks! I had to do a thing where they reset my cookie because I only used my email address before, not openID, so I never actually made and account, but you're checked now. Thanks again!
Seth Vargo
@Seth - You're welcome. Glad it worked! :o)
patrick dw
+1  A: 

Are you sure it's not an issue with your PHP?

It works fine for me (using alternate http requests).

Test it here: http://jsfiddle.net/kkxBH/1/ (updated)

Of course, items appended into the same column may not get appended in the same order as they were sent. But rather in the order in which the response is received. Not necessarily the same.

EDIT: Updated to ensure proper order.

moduleList = [['weather','test'],['test'],['some','other']];

request = ['http://www.microsoft.com',
           'http://www.apple.com',
           'http://www.google.com'];


for(i in moduleList) {
    for(j in moduleList[i]) {
        addModule(i,moduleList[i][j], j); //column,name, j index
    }
}

    // Receive "j" from inner for() loop
function addModule(column,name, j) {

         // Reference the column
    var $column = $('#'+column);

         // Append a new <span> tag to the column that has
         //   the value of "j" as the class name
    $('<span/>',{ className:j }).appendTo($column);

    $.get(request[column],function() {
           // Append the result to the proper span in the proper column.
           // (Of course, you'll be appending your data returned.)
        $column.find('span.' + j).append(name);
    });
}​
patrick dw