title: JavaScript auto-incrementing a variable in jQuery and AJAX
body: <p>I have JavaScript using jQuery and AJAX which creates a dynamic array, which has some values used for AJAX request as below;</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var array = Array("y","y","x","y","y","y");
  function updateBackground(cellId, titleId) {
      var i = 0;
      $.ajax({
          type: "POST",
          url: "ajax.php",
          data: {
            filename: Array(array[i], "testdata", $("#"+titleId).html())
          },
          success: function(response){
            $("#"+cellId).css("background-image", "url('pdfthumb/" + response + "')");
          }
      });
  i++;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>The script is suppose to submit values in the array in <code>array[i]</code> for each AJAX request. I made a variable <code>var i</code> which auto increments.. But the script is not working.. The script works well if <code>array[i]</code> is replaced by <code>array[0]</code> or <code>array[1]</code> etc..</p>
  
  <p>How can I solve the syntax error?</p>