如何在AJAX Complete上访问选择器?

时间:2018-11-27 16:38:14

标签: javascript jquery ajax

我发出一个Ajax请求,该请求将后端的HTML内容添加到页面,然后发出另一个Ajax Request,该请求修改动态添加的HTML。

    $("#list-customers-button").click(function () {
        var selectedAcquirer = $("#acquirer-select").val();
        if (selectedAcquirer === "adyen") {
            if (listed) {
                listed = false;
                $("#customer-list-area").hide().html('').fadeIn(fadeTime);
            } else {
                listed = true;
                $.ajax({
                    type: "GET",
                    url: "/adyen_list_customers",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function () {
                        $("#list-progress").show();
                    },
                    success: function (data) {
                        console.log(JSON.stringify(data));
                        $("#customer-list-area").hide().html(data["response_html"]).fadeIn(fadeTime).promise().done(function () {
                            $(".collapsible").collapsible();
                            resetDatepicker();

                        });

                    },
                    complete: function () {
                        $(document).on("change", "#file-download-datepicker", function () {
                            $("#file-download-progress").hide();
                            $("#file-download-date").val(selectedDate);
                            fileDownloadData = $("#file-download-form").serialize();
                            displayMessage(fileDownloadData);
                            $.ajax({
                                type: "POST",
                                url: "/adyen_update_file_list_by_date",
                                data: fileDownloadData,
                                beforeSend: function () {
                                    $("#file-download-progress").show();
                                },
                                success: function (response) {

                                },
                                complete: function (response) {
                                    $("#file-download-progress").hide();
                                    console.log(response.responseText);
                                    // Doesn't work. Selector should exist, but it doesn't.
                                    $("#merchant-file-list").html(response.responseText); 
                                },
                                error: function (response) {
                                    displayMessage(response["responseText"]);
                                }
                            });
                        });
                    },
                    error: function (data) {
                        displayMessage(data);
                    },
                });
            }
        } else if (selectedAcquirer === "stone") {
            displayMessage("Adquirente indisponível no momento.");
        } else {
            displayMessage("É necessário selecionar uma adquirente.");
        }
    });

我从服务器获得了完美的HTML响应,但是以前也从服务器中添加了HTML的选择器(#file-download-progress,#merchant-file-list)被完全忽略了。 .html()不起作用,也不起作用,我也不知道如何使用.on()解决此问题,因为我只需要访问该内容。由于ajax请求是在上一个请求完成之后发出的,因此应该可以被访问。他们只是没有及时存在。

0 个答案:

没有答案