title: JavaScript loop - Ajax image animation asp.net MVC
body: <p>My application is asp.net MVC, I am using the following script to change Z axis of a 3D image and display the resulted images as animation:</p>
  
  <pre><code>  for (var i = 1; i &lt; 202 * sThickness; i++) {
                  $.ajax({
                      url: '/Home/Rotate3D',
                      type: 'POST',
                      data: {
                          pX: 0,
                          pY: 0,
                          pZ: i * sThickness,
                          udm: ++udm
                      },
                      success: function () {
                          dicom1.src = '&lt;%=Url.Action("Rotate3DImage")%&gt;';
                        //  alert(i);
                      },
                      error: function () {
                      }
                  });
  </code></pre>
  
  <p>The first action in the controller "Rotate3D":</p>
  
  <pre><code>public ActionResult Rotate3D(float pX = 0, float pY = 0, float pZ = 0, int inc = 0)
      {
          DicomImage3D im = null;
          im = MySession.Current.mpr as DicomImage3D;
          im.SetViewPlane(new Point3D(pX, pY, pZ), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0));
          MySession.Current.dicomImage = im;
          return Json(new { success = true, inc = inc }, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>The second action to make the image:</p>
  
  <pre><code> public ActionResult Rotate3DImage()
      {
          FileContentResult data;
          Image objImage = null;
          DicomImage3D im = null;
          im = MySession.Current.dicomImage as DicomImage3D;
     ......;
          using (var memStream = new MemoryStream())
          {
              objImage.Save(memStream, ImageFormat.Png);
              data = this.File(memStream.GetBuffer(), "image/png");
          }
          return data;
      }
  </code></pre>
  
  <p>I works but does not display each image just jump to the last image, when I added alert, I get 127!!  Any suggetions, thanks in advance.</p>