Friday, October 25, 2013

Simple #Jquery quiz question of the day... what's wrong with this code?


Hi folks,
I ran into this problem the other day and thought I might share it with you all... I'll put the answer in a comment in a few da... Feel free to post alternate solutions... or, call me a tweed... or whatever :)
So long, and thanks for all the fish.

Question:

What is wrong with this?? What will happen when it runs?

//Question Assuming that test.json is has the appropriate data that the success function
// requires, why is this a poor piece of code?
$(document).ready(function(){
for (var i=1; i <= 5; i++)
{
var url = "http://somewebresource.com/test" + i + ".json";
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function(data){
$("#qa"+i+"1").html(data[1][1]);
$("#qa"+i+"2").html(data[1][2]);
$("#qa"+i+"3").html(data[1][3]);
$("#qa"+i+"4").html(data[1][4]);
$("#qa"+i+"5").html(data[1][5]);
}
});
}
});

Oh jeez... 

i'm itching to show you... but it'll be more fun if you guess.


The answer coming back soon!

No comments:

Post a Comment