我根据AJAX请求的成功/响应创建MaterializeCSS的datepicker:
$("#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));
// Here <<<<<<<<<<<<< Code comes from the server.
$("#customer-list-area").hide().html(data["response_html"]).fadeIn(fadeTime).promise().done(function() {
$(".collapsible").collapsible();
resetDatepicker();
$("#file-download-progress").hide();
});
},
complete: function() {
},
error: function (data) {
displayMessage(data);
},
});
}
} else if (selectedAcquirer === "stone") {
displayMessage("Adquirente indisponível no momento.");
} else {
displayMessage("É necessário selecionar uma adquirente.");
}
});
我重置了所有的日期选择器以使JS正常工作,并且日期选择器正常运行(所有国际化等)。问题是,当我在它的更改事件上发送请求时,它的值为空。
$(document).on("change", "#file-download-date-datepicker", function() {
fileDownloadData = $("#file-download-form").serialize();
displayMessage($("#file-download-date-datepicker").text());
$.ajax({
type: "POST",
url: "/adyen_update_file_list_by_date",
data: fileDownloadData,
beforeSend: function () {
$("#file-download-progress").show();
},
success: function (response, status, xhr) {
$("#merchant-file-list").html(response);
},
complete: function (response) {
$("#file-download-progress").hide();
},
error: function (response) {
displayMessage(response["responseText"]);
}
});
});
这是表格:
<form id='file-download-form'>
<div class='input-field col s8'>
<input id='file-download-date-datepicker' name='file-download-date' type='text' class='datepicker'>
<label for='file-download-date'>Data</label>
</div>
<input id='file-download-pfj' name='file-download-pfj' type='text' value='{customer['pfj']}' hidden>
<input id='file-download-merchant' name='file-download-merchant' type='text' value='{merchant}' hidden>
</form>
这没有意义,因为其他输入正常。问题特别是与日期选择器有关,不包含其值。 .val()返回空。我怀疑这是因为我正在动态生成它。奇怪的是,在我初始化它之后,它的js可以正常工作。