Py学习  »  Jquery

在jQuery中,如何在每次之后执行代码

Jeppe Donslund • 4 年前 • 1752 次点击  

我需要在jQuery之后执行som代码。每个

我试着在每次循环后编写它,但它会立即执行。 我试过了。承诺。完成,但这给了我一个错误,promise()不是函数。

我的密码

$("#loader").show();
            var url = $(this).attr("action");
            var formData = new FormData($(this)[0]);
            $(this).hide(); 
            $.ajax({
                url: "generateJson.php",
                type: 'POST',
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                enctype: 'multipart/form-data',
                processData: false,
                success: function (data, status)
                {
                    $('#json').append(data); //content loads here

                },
                error: function (xhr, desc, err)
                {
                    console.log("error");
                }
            }).done(function( data ) {
                data = JSON.parse( $("#json").val() );
                //console.log(data.length);
                $.each( data, function( key, val ) {
                    console.log(val);
                    //$("#result").append(val);
                    $.ajax({
                        type: "POST",
                        url: "/generateInvoice.php",
                        dataType: "html",
                        data: val,
                        success: function (data, status) {
                            //console.log(data);
                            if (data) {
                                $("#result").append(data)
                            //  console.log("Hurray");
                            } else {
                                console.log("Error");
                            }
                        },
                        error: function (xhr, desc, err)
                        {
                            console.log("error: " + desc + " " + err);
                        }
                    });
                }).promise().done(function(){
                    $("#loader").hide();
                    $("#done").show();
                });
                
                
            });
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/127993
文章 [ 1 ]  |  最新文章 4 年前