[英]Very peculiar - submit once the first time, twice the 2nd time, trice the 3rd time .. and so on .. what I did wrong?
[英]ajax form being submitted twice on 2nd submit, 3 times on 3rd submit, etc
由于某种原因,如果您不刷新两者之间的页面,则在第一个“提交”中提交一次我的表单,然后在第二个“提交”中提交两次。
$(document).on('submit', ".post-video-form", function(uploadVideo) {
uploadVideo.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
type: 'post',
url: '/dev/new/scripts/upload_video.php',
data: formData,
success: function (response) {
if (response == 'success') {
$(".overlay").fadeOut(200);
setTimeout(function() {
$(".overlay").remove();
}, 250);
setTimeout(function() {
$(".head").before(overlay_success_html);
$(".overlay").fadeIn();
}, 255);
$(document).on('click', ".close-overlay", function(){
$(".overlay").fadeOut(200);
setTimeout(function() {
$(".overlay").remove();
}, 250);
});
}
if (response == 'failed') {
$(".upload-error").append('Upload error: File must be a JPG or PNG less than 2.0MB');
}
},
error: function() {
$(".upload-error").append('Upload error: File must be a JPG or PNG less than 2.0MB');
},
cache: false,
contentType: false,
processData: false
});
});
您将需要查看更多代码,但也许您的提交处理程序正在为每条发布额外的时间注册。
尝试在之前添加控制台日志或在线警报
$(document).on('submit', ".post-video-form", function(uploadVideo) {
以确保提交事件没有被多次注册。 如果您正在生成javascript服务器端,则可能是这种情况。 否则,我们将需要更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.