title: why is my [i] always 10 Ajax
body: <p>im using the Flickr api <a href="http://flickr" rel="nofollow noreferrer">https://www.flickr.com/services/api/explore/flickr.photos.search</a> to get some fotos, i already got the fotos and have a input where the user can specify how many fotos he want, the thing is, i need to work with the getsize flicker service, to pass him a id, and then based on where the user clicked(i have some buttons for different sizes) he should give me the specific size, but i have a problem, my first Ajax request return me some data, with the xml specific to the photos, the second Ajax request that is inside the succes of the first one, gives me the different sizes for the specific photo i must just pass the Id, here is the code that shows what i talked about:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;html lang="en"&gt;
  
  &lt;head&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"&gt;
      &lt;style type="text/css"&gt;
          #sq,
          #lg-sq,
          #thumb,
          #small,
          #mid,
          #ori {
              width: 100%
          }
  
          input {
              width: 50px;
          }
      &lt;/style&gt;
      &lt;script type="text/javascript" src="FlickrPhotosSearch.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;h2&gt;Escolha o tamanho das imagens (em píxeis) que quer visualizar&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-2"&gt;
                  &lt;button type="button" class="btn btn-primary" id="sq"&gt;Square [75X75]&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-md-2"&gt;
                  &lt;button type="button" class="btn btn-primary" id="lg-sq"&gt;Large Square&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-md-2"&gt;
                  &lt;button type="button" class="btn btn-primary" id="thumb"&gt;Thumbnail&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-md-2"&gt;
                  &lt;button type="button" class="btn btn-primary" id="small"&gt;Small&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-md-2"&gt;
                  &lt;button type="button" class="btn btn-primary" id="mid"&gt;Medium&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;h2&gt;Pesquisa de fotos&lt;/h2&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-lg-2"&gt;
                  &lt;input type="text" class="form-control" id="tag"&gt;
              &lt;/div&gt;
              &lt;div class="col-lg-1"&gt;
                  &lt;button type="button" class="btn btn-success" id="pesquisar"&gt;Pesquisar&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-lg-1"&gt;
                  &lt;button type="button" class="btn btn-alert" id="apagar"&gt;Apagar&lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="col-lg-2"&gt;
                  &lt;input type="text" id="numero" class="form-control" placeholder="numero de fotos"&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;hr&gt;
  
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;div id="results"&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>$(document).ready(function () {
      var numero = 10;
      var clicked = 1;
  
      $("#sq").click(function(){
          clicked = 1;
      });
       $("#lg-sq").click(function(){
          clicked = 2;
      });
       $("#thumb").click(function(){
          clicked = 3;
      });
       $("#small").click(function(){
          clicked = 4;
      });
       $("#mid").click(function(){
          clicked = 5;
      });
  
      $("#apagar").click(function () {
          $("#results").html('');
      });
  
      $('#pesquisar').click(function () {
          $("#results").html('');
          $.ajax({
              url: 'https://api.flickr.com/services/rest/?method=flickr.photos.search',
              dataType: 'xml',
              data: {
                  api_key: '2fd41b49fedfd589dc265350521ab539',
                  tags: $("#tag").val(),
                  format: 'rest'
              },
              success: sucessHandler,
              error: errorHandler
  
          });
  
          function sucessHandler(data) {
              var fotos = $(data).find("photo");
  
              if ($("#numero").val() != "") {
                  numero = parseInt($("#numero").val());
                  console.log("entrou");
              }
  
              for (var i = 0; i &lt; numero; i++) {
                  $.ajax({
                      url: 'https://api.flickr.com/services/rest/?method=flickr.photos.getSizes',
                      dataType: 'xml',
                      data: {
                          api_key: '2fd41b49fedfd589dc265350521ab539',
                          photo_id: $(fotos[i]).attr('id'),
                          format: 'rest'
                      },
                      success: function(dataSize){
                           console.log(i);
                           var farmId = $(fotos[i]).attr('farm');
                           var serverId= $(fotos[i]).attr('server');
                           var Id = $(fotos[i]).attr('id');
                           var secret = $(fotos[i]).attr('secret');
                           var src = "https://farm" + farmId + ".staticflickr.com/"+ serverId +"/" + Id + "_"+secret+".jpg";
  
                          $('#results').append("&lt;img src ="+src+" width='100' height='100'&gt;");
                      },
                      error: errorSize
  
                  });
              }
  
                  function errorSize(req, status, err) {
                      console.log("error size");
                  }
  
          }
  
          function errorHandler(req, status, err) {
              console.log("fail");
          }
      });
  });
  </code></pre>
  
  <p><strong>i get always the same image, if i dont specific the number of fotos i want i get 10(var number = 10) but all the fotos are the same, i did a console log and the [i] is always 10, what is wrong here ?:S</strong></p>