日期:2014-05-16  浏览次数:20656 次

forloop中执行ajax
  var imgs = document.querySelectorAll(".obj");
            for (var i = 0; i < imgs.length; i++) {
                data = imgs[i].value;
                $.ajax({
                    type: "POST",
                    url: "ajax.ashx",
                    data: { data: data },
                    beforeSend: function() {
                        $("#image1").css("display", "inline");
                    }
                })
                 .done(function(data) {
                     if (data == 1 || data == "1") {
                         var result = $("<p>Successful</p>");
                         $('#fileList').append(result);
                     }
                     else {
                         var result = $("<p>upload fail</p>");
                         $('#fileList').append(result);
                     }
                     $("#image1").css("display", "none");
                 })
                 .fail(function() { alert("error"); });
                $("#image1").css("display", "none");
            }


这样子好像是同时发送多个ajax请求 ,我想让他完成了一次请求才继续运行 forloop ,不知道要怎么写 ! 高手指导一下我吧 ,万分感激 !