Пожалуйста, если кто-нибудь может помочь в попытке выяснить, как это работает и как я могу отправить данные формы с ним?
Ниже приведен код Javascript, который отправляет запрос ajax на контроллер mvc, который долженсодержат данные формы, а также не только файлы, которые я получаю (request.files) в mvc.
Обратите внимание, что идентификатор формы "CF5aca6f3602033", класс формы - "CF5aca6f3602033 caldera_forms_form cfajax-trigger", data-идентификатор формы - "CF5aca6f3602033", целевой объект - "# caldera_notices_1", шаблон - "# cfajax_CF5aca6f3602033-tmpl", data-cfajax - "CF5aca6f3602033"
var resBaldrickTriggers;
jQuery(function(a) {
var b = [],
c = function(c, d, e) {
console.log("hello1");
var f = a("#progress-file-" + d),
g = a("." + d + " .file-size");
b.push(1), cf_uploader_filelist[d].state = 2, a.ajax({
xhr: function() {
var a = new window.XMLHttpRequest;
return a.upload.addEventListener("progress", function(a) {
if (a.lengthComputable) {
var b = a.loaded / a.total * 100;
f.width(b + "%"), g.html(size_format(a.loaded) + " / " + size_format(a.total))
}
}, !1), a.addEventListener("progress", function(a) {
if (a.lengthComputable) {
a.loaded, a.total
}
}, !1), a
},
//url: c.data("request") + "/upload/",
url:"/home/Upload/",
type: "POST",
data: e,
processData: !1,
contentType: !1,
success: function(e, f, g) {
console.log("test data");
console.log(e);
if (e.success && !0 === e.success) {
b.pop();
var h = a('[data-file="' + d + '"]');
h.next().addClass("file-uploaded"), h.remove(), cf_uploader_filelist[d].state = 3, c.submit()
} else if (e.data && !e.success) return a("." + d).addClass("has-error"), c.find(":submit").prop("disabled", !1), c.find(".cf-uploader-trigger").slideDown(), void a("." + d + " .file-error").html(e.data)
},
error: function(a, b, d) {
c.data("postDisable") || buttons.prop("disabled", !1)
}
})
};
(resBaldrickTriggers = function() {
var d = function(b) {
return a("#caldera_notices_" + b.params.trigger.data("instance"))
},
e = function(b) {
return a("#caldera-forms-breadcrumb_" + b.params.trigger.data("instance"))
},
f = function(a) {
var b = e(a);
b.length && b.show().attr("aria-hidden", !1).css("visibility", "visible")
},
g = function(a) {
var b = e(a);
b.length && b.show().attr("aria-hidden", !0).css("visibility", "hidden")
};
console.log(b);
console.log(b.params);
a(".cfajax-trigger").baldrick({
request: "./",
method: "POST",
init: function(d, e) {
e.preventDefault();
console.log("hello3");
var f = a(d),
g = f.find(":submit");
if (f.data("_cf_manual")) return f.find('[name="cfajax"]').remove(), !1;
if (f.data("postDisable") || g.prop("disabled", !0), "object" == typeof cf_uploader_filelist) {
f.find(".cf-uploader-trigger").slideUp();
var h = !1,
i = b.length;
for (var j in cf_uploader_filelist)
if (!(cf_uploader_filelist[j].state > 1 || 0 === cf_uploader_filelist[j].state)) {
h = !0;
var k = new FormData,
l = j,
m = a("#" + l.split("_file_")[0]);
if (k.append(m.data("field"), cf_uploader_filelist[j].file), k.append("field", m.data("field")), k.append("control", m.data("controlid")), c(f, l, k), m.val(""), m.attr("type", "hidden"), m.val(m.data("controlid")), 1 === ++i) break
} if (!0 === h || b.length) return !1
}
},
error: function(b) {
if (404 === b.jqxhr.status) this.trigger.data("_cf_manual", !0).trigger("submit");
else {
var c = d(b);
b.jqxhr.responseJSON.data.html && (c.html(b.jqxhr.responseJSON.data.html), a("html,body").animate({
scrollTop: c.offset().top - c.outerHeight()
}, 300))
}
},
callback: function(b) {
b.params.trigger.find(":submit").prop("disabled", !1);
var c = d(b);
if (b.params.trigger.data("customCallback") && "function" == typeof window[b.params.trigger.data("customCallback")] && window[b.params.trigger.data("customCallback")](b.data), b.params.trigger.data("inhibitnotice") || (a(".caldera_ajax_error_wrap").removeClass("caldera_ajax_error_wrap").removeClass("has-error"), a(".caldera_ajax_error_block").remove(), "complete" === b.data.status || "success" === b.data.type ? (g(b), b.data.html && b.params.target.html(b.data.html), b.params.trigger.data("hiderows") && b.params.trigger.find("div.row").remove()) : "preprocess" === b.data.status ? (f(b), b.params.target.html(b.data.html)) : "error" === b.data.status && (f(b), b.params.target.html(b.data.html))), "complete" !== b.data.status && "success" !== b.data.type || b.data.entry || b.params.trigger[0].reset(), b.data.url && (b.params.trigger.hide(), window.location = b.data.url), b.params.trigger.find(".cf-uploader-trigger").slideDown(), b.data.fields)
for (var e in b.data.fields) {
console.log(e);
var h = b.params.trigger.find('[data-field="' + e + '"]'),
i = h.parent();
if (h.length) {
i.is("label") && (i = i.parent(), (i.hasClass("checkbox") || i.hasClass("radio")) && (i = i.parent()));
var j = i.find(".help-block").not(".caldera_ajax_error_block");
i.addClass("has-error").addClass("caldera_ajax_error_wrap"), j.length && j.hide(), i.append('<span class="help-block caldera_ajax_error_block">' + b.data.fields[e] + "</span>")
} else c.html('<p class="alert alert-danger ">' + b.data.fields[e] + "</p>")
}
if ("undefined" != b.data.scroll) {
var k = document.getElementById(b.data.scroll);
if (null != k) {
var l = a(k);
a("html,body").animate({
scrollTop: l.offset().top - l.outerHeight() - 12
}, 300)
}
}
a(document).trigger("cf.submission", b), a(document).trigger("cf." + b.data.type)
}
})
})()
});
var resBaldrickTriggers;
jQuery(function(a) {
var b = [],
c = function(c, d, e) {
console.log("hello4");
var f = a("#progress-file-" + d),
g = a("." + d + " .file-size");
b.push(1), cf_uploader_filelist[d].state = 2, a.ajax({
xhr: function() {
var a = new window.XMLHttpRequest;
return a.upload.addEventListener("progress", function(a) {
if (a.lengthComputable) {
var b = a.loaded / a.total * 100;
f.width(b + "%"), g.html(size_format(a.loaded) + " / " + size_format(a.total))
}
}, !1), a.addEventListener("progress", function(a) {
a.lengthComputable && (a.loaded, a.total)
}, !1), a
},
//url: c.data("request") + "/upload/",
url: "/home/upload/",
type: "POST",
data: e,
processData: !1,
contentType: !1,
success: function(e, f, g) {
console.log($('form').serialize());
if (e.success && !0 === e.success) {
console.log(e);
b.pop();
var h = a('[data-file="' + d + '"]');
h.next().addClass("file-uploaded"), h.remove(), cf_uploader_filelist[d].state = 3, c.submit()
} else if (e.data && !e.success) return a("." + d).addClass("has-error"), c.find(":submit").prop("disabled", !1), c.find(".cf-uploader-trigger").slideDown(), void a("." + d + " .file-error").html(e.data)
},
error: function(a, b, d) {
c.data("postDisable") || buttons.prop("disabled", !1)
}
})
};
(resBaldrickTriggers = function() {
a(".cfajax-trigger").baldrick({
request: "./",
method: "POST",
init: function(d, e) {
e.preventDefault();
var f = a(d),
g = f.find(":submit");
if (f.data("_cf_manual")) return f.find('[name="cfajax"]').remove(), !1;
if (f.data("postDisable") || g.prop("disabled", !0), "object" == typeof cf_uploader_filelist) {
f.find(".cf-uploader-trigger").slideUp();
var h = !1,
i = b.length;
for (var j in cf_uploader_filelist)
if (!(cf_uploader_filelist[j].state > 1 || 0 === cf_uploader_filelist[j].state)) {
h = !0;
var k = new FormData,
l = j,
m = a("#" + l.split("_file_")[0]);
if (k.append(m.data("field"), cf_uploader_filelist[j].file), k.append("field", m.data("field")), k.append("control", m.data("controlid")), c(f, l, k), 1 === ++i) break
} if (!0 === h || b.length) return !1
}
},
error: function(a) {
404 === a.jqxhr.status && this.trigger.data("_cf_manual", !0).trigger("submit")
},
callback: function(b) {
if (b.params.trigger.find(":submit").prop("disabled", !1), b.params.trigger.data("instance"), b.params.trigger.data("customCallback") && "function" == typeof window[b.params.trigger.data("customCallback")] && window[b.params.trigger.data("customCallback")](b.data), b.params.trigger.data("inhibitnotice") || (a(".caldera_ajax_error_wrap").removeClass("caldera_ajax_error_wrap").removeClass("has-error"), a(".caldera_ajax_error_block").remove(), "complete" === b.data.status || "success" === b.data.type ? (b.data.html && b.params.target.html(b.data.html), b.params.trigger.data("hiderows") && b.params.trigger.find("div.row").remove()) : "preprocess" === b.data.status ? b.params.target.html(b.data.html) : "error" === b.data.status && b.params.target.html(b.data.html)), "complete" !== b.data.status && "success" !== b.data.type || b.data.entry || b.params.trigger[0].reset(), b.data.url && (b.params.trigger.hide(), window.location = b.data.url), b.params.trigger.find(".cf-uploader-trigger").slideDown(), b.data.fields)
for (var c in b.data.fields) {
var d = b.params.trigger.find('[data-field="' + c + '"]'),
e = d.parent();
e.is("label") && (e = e.parent(), (e.hasClass("checkbox") || e.hasClass("radio")) && (e = e.parent()));
var f = e.find(".help-block").not(".caldera_ajax_error_block");
e.addClass("has-error").addClass("caldera_ajax_error_wrap"), f.length && f.hide(), e.append('<span class="help-block caldera_ajax_error_block">' + b.data.fields[c] + "</span>")
}
a(document).trigger("cf.submission", b), a(document).trigger("cf." + b.data.type)
}
})
})()
});