jQuery Ajax post and response evaluation
<p>I am relatively new to JavaScript and jQuery in particular, so please bear with me, I am trying to loop through multiple <code>&lt;form&gt;</code>s and then <code>serialize()</code> the data with jQuery and post it using Ajax to my page. This is happening alright, the data is posted, my PHP script echos 1 and everything is taken care off, but for some strange reason, the following code is not working, especially the "success" variable -- it's not increasing at all! What is wrong here?</p>

<pre><code>$('.submitB').click(function(){

      var success = 0;
      var times = 0;
      var alertText;


  $('.input').each(function(){

      times++;

      var serializedForms = $(this).serialize();

      $.post('&lt;?=$this-&gt;config-&gt;site_url()?&gt;crud/additem/forms', serializedForms ,function(data){
          if (data)
          {
              success++;
          }
          });
  });

      if (times)
          {
              alertText = "تم إدخال " + success + " مدخل من إصل " + times + " بنجاح.";
              alert(alertText);
          }

})
</code></pre>

<p>(The Arabic text just says "<code>success</code> + Entries from + <code>times</code> + were entered successfully.")</p>
