在控制器中保存图像后,ajax成功后,页面将自动重新加载。如果图像不可用,则没有问题。如何停止重新加载页面?
方法
if (desktopImageUpload != null)
{
var file = desktopImageUpload;
var fileFormat = Path.GetFileName(file.ContentType);
var fileName = "promo-" + fileID + "-desktop." + fileFormat;
var path = Path.Combine(Server.MapPath("~/Images/SocialMediaPromotions"), fileName);
file.SaveAs(path);
}
ajax
$.ajax({
type: 'POST',
dataType: 'JSON',
url: '/Admin/RecordSocialMediaPromotions',
data: formData,
contentType: false,
processData: false,
success: function (response) {
if (response.type == "Success") {
swal("Hooray", "Promotion Recorded Successfully", "success");
$('#preLoader').hide();
$("#dealSaveBtn").prop("disabled", true);
} else {
swal("Boooo", response.msg, "error");
$('#preLoader').hide();
}
},
error: function (response) {
swal("Boooo", "Promotion was not recorded", "error");
$('#preLoader').hide();
}
});
答案 0 :(得分:0)
如果您的“按钮”是button
元素,请确保您明确设置了type
属性,否则WebForm将默认将其视为“提交”。
<button id="dealSaveBtn" type="button">Go</button>
如果它是input
元素,请尝试以下操作:
e.preventDefault();