在将图像添加到字段中时,即使在处理完成后,加载程序仍然仍在加载。我已经使用ajax.can提交了表单,我知道无限加载的原因是什么?我的代码在
之下 $('.port_load').waitMe({
effect: 'win8',
text: 'Please Wait...',
bg: 'rgba(255,255,255,0.85)',
color: '#000',
maxSize: '',
source: 'img.svg',
onClose: function() {}
});
这是我提交的完整代码
$('#port_form').submit(function(e){
e.preventDefault();
$('.port_load').waitMe({
effect: 'win8',
text: 'Please Wait...',
bg: 'rgba(255,255,255,0.85)',
color: '#000',
maxSize: '',
source: 'img.svg',
onClose: function() {}
});
if($('#img1').val()!='' && $('#p_img').val()==''){//for editing
$.ajax({
url:'../api_fle/port',
method:'POST',
data:{u_id:$('#uId').val(),title:$('#p_title').val(),desc:$('#p_description').val(),
link:$('#img1').val(),pId:$('#p_id').val()},
success:function(data){
$('.port_load').waitMe('hide');
if(data==0){
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again.</p>');
}else{
$('#wrng').html('');
$('#myModal5').modal('hide');
$("#p_img").replaceWith($("#p_img").val('').clone(true));
$('#p_title').val('');
$('#p_description').val('');
$('#p_id').val('');
$('#img1').val('');
swal({
title: "Success",
text: "Successfully Inserted",
timer: 1000,
showConfirmButton: false
});
on_load();
}
}
});
}else{// adding new
$.ajax({
url:'../api_fle/img_upload',
method:'POST',
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success:function(data){
if(data==0){
$('.port_load').waitMe('hide');
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again</p>');
}else if(data==1){
$('.port_load').waitMe('hide');
$('#wrng').html('<p style="text-align: center; color:red;">Upload Image only!</p>');
}else{
$('#wrng').html("");
var link="http://www.udyomitra.com/photos/"+$('#uId').val()+"/gallery/"+data;
$.ajax({
url:'../api_fle/port',
method:'POST',
data:{u_id:$('#uId').val(),title:$('#p_title').val(),desc:$('#p_description').val(),
link:link,pId:$('#p_id').val()},
success:function(data){
$('.port_load').waitMe('hide');
if(data==0){
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again</p>');
}else{
$('#wrng').html("");
$('#myModal5').modal('hide');
$("#p_img").replaceWith($("#p_img").val('').clone(true));
$('#p_title').val('');
$('#p_description').val('');
$('#p_id').val('');
$('#img1').val('');
swal({
title: "Success",
text: "Successfully Inserted",
timer: 1000,
showConfirmButton: false
});
on_load();
}
}
});
}
}
});
}
});
答案 0 :(得分:0)
只需使用
$('.port_load').waitMe('hide');
更具体地针对您的问题
$(document).ready(function(){
$(document).ajaxStart(function(){
$('.port_load').waitMe({
effect: 'win8',
text: 'Please Wait...',
bg: 'rgba(255,255,255,0.85)',
color: '#000',
maxSize: '',
source: 'img.svg',
onClose: function() {}
});
});
$(document).ajaxStop(function(){
$('.port_load').waitMe('hide');
});
$('#port_form').submit(function(e) {
e.preventDefault();
if ($('#img1').val() != '' && $('#p_img').val() == '') { //for editing
$.ajax({
url: '../api_fle/port',
method: 'POST',
data: {
u_id: $('#uId').val(),
title: $('#p_title').val(),
desc: $('#p_description').val(),
link: $('#img1').val(),
pId: $('#p_id').val()
},
success: function(data) {
if (data == 0) {
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again.</p>');
} else {
$('#wrng').html('');
$('#myModal5').modal('hide');
$("#p_img").replaceWith($("#p_img").val('').clone(true));
$('#p_title').val('');
$('#p_description').val('');
$('#p_id').val('');
$('#img1').val('');
swal({
title: "Success",
text: "Successfully Inserted",
timer: 1000,
showConfirmButton: false
});
on_load();
}
}
});
} else { // adding new
$.ajax({
url: '../api_fle/img_upload',
method: 'POST',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data) {
if (data == 0) {
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again</p>');
} else if (data == 1) {
$('#wrng').html('<p style="text-align: center; color:red;">Upload Image only!</p>');
} else {
$('#wrng').html("");
var link = "http://www.udyomitra.com/photos/" + $('#uId').val() + "/gallery/" + data;
$.ajax({
url: '../api_fle/port',
method: 'POST',
data: {
u_id: $('#uId').val(),
title: $('#p_title').val(),
desc: $('#p_description').val(),
link: link,
pId: $('#p_id').val()
},
success: function(data) {
if (data == 0) {
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again</p>');
} else {
$('#wrng').html("");
$('#myModal5').modal('hide');
$("#p_img").replaceWith($("#p_img").val('').clone(true));
$('#p_title').val('');
$('#p_description').val('');
$('#p_id').val('');
$('#img1').val('');
swal({
title: "Success",
text: "Successfully Inserted",
timer: 1000,
showConfirmButton: false
});
on_load();
}
}
});
}
}
});
}
});
});
答案 1 :(得分:0)
您是否尝试在ajaxComplete()或ajaxError()之类的其他事件处理程序中删除您的加载器,您可以在成功处理程序之后链接它们;
$(document).ready(function(){
$(document).ajaxStart(function(){
$('.port_load').waitMe({
effect: 'win8',
text: 'Please Wait...',
bg: 'rgba(255,255,255,0.85)',
color: '#000',
maxSize: '',
source: 'img.svg',
onClose: function() {}
});
});
$(document).ajaxStop(function(){
$('.port_load').waitMe('hide');
});
$('#port_form').submit(function(e) {
e.preventDefault();
if ($('#img1').val() != '' && $('#p_img').val() == '') { //for editing
$.ajax({
url: '../api_fle/port',
method: 'POST',
data: {
u_id: $('#uId').val(),
title: $('#p_title').val(),
desc: $('#p_description').val(),
link: $('#img1').val(),
pId: $('#p_id').val()
},
success: function(data) {
if (data == 0) {
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again.</p>');
} else {
$('#wrng').html('');
$('#myModal5').modal('hide');
$("#p_img").replaceWith($("#p_img").val('').clone(true));
$('#p_title').val('');
$('#p_description').val('');
$('#p_id').val('');
$('#img1').val('');
swal({
title: "Success",
text: "Successfully Inserted",
timer: 1000,
showConfirmButton: false
});
on_load();
}
},
complete : function(){},
error : function(){}
});
} else { // adding new
$.ajax({
url: '../api_fle/img_upload',
method: 'POST',
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data) {
if (data == 0) {
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again</p>');
} else if (data == 1) {
$('#wrng').html('<p style="text-align: center; color:red;">Upload Image only!</p>');
} else {
$('#wrng').html("");
var link = "http://www.udyomitra.com/photos/" + $('#uId').val() + "/gallery/" + data;
$.ajax({
url: '../api_fle/port',
method: 'POST',
data: {
u_id: $('#uId').val(),
title: $('#p_title').val(),
desc: $('#p_description').val(),
link: link,
pId: $('#p_id').val()
},
success: function(data) {
if (data == 0) {
$('#wrng').html('<p style="text-align: center; color:red;">Something went Wrong! Try again</p>');
} else {
$('#wrng').html("");
$('#myModal5').modal('hide');
$("#p_img").replaceWith($("#p_img").val('').clone(true));
$('#p_title').val('');
$('#p_description').val('');
$('#p_id').val('');
$('#img1').val('');
swal({
title: "Success",
text: "Successfully Inserted",
timer: 1000,
showConfirmButton: false
});
on_load();
}
}
});
}
}
});
}
});
});