code_junkie

Javascript order of execution - How come it does this?

Nov 13th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. window.ratingCallback = function(data){
  2.  
  3. if(data[0].code == 3){
  4. ratingHTML = buildHTML(0);
  5. console.log('a'+ratingHTML);
  6. return;
  7. }
  8.  
  9. ratingHTML = buildHTML(data[0].rating);
  10. console.log('b'+ratingHTML);
  11. return;
  12. };
  13.  
  14. function buildHTML(pageRating){
  15.  
  16. for(counter = 1; counter <= 5; counter++){
  17.  
  18. if(counter == pageRating){
  19. ratingHTML += '<input name="star1" type="radio" class="star" value="'+counter+'" checked="checked"/>';
  20. } else {
  21. ratingHTML += '<input name="star1" type="radio" class="star" value="'+counter+'"/>';
  22. }
  23. }
  24.  
  25. return ratingHTML;
  26. }
  27.  
  28.  
  29. $.getJSON("https://domain.com/"+data+"?jsoncallback=?");
  30.  
  31. console.log(ratingHTML+"WHY DOES THIS EXECUTE FIRST AND NOT AFTER THE CALLBACK SINCE IT IS PLACED AFTER getJSON????");
Add Comment
Please, Sign In to add comment