[英]How to stop refreshing page after ajax call (only happening while saving a image)?
After saving an image in controller, the page is getting reload automatically after ajax success. 在控制器中保存图像后,页面将在ajax成功后自动重新加载。 If image is not available, there is no issue.
如果图像不可用,则没有问题。 how to stop reloading the page?
如何停止重新加载页面?
Method 方法
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(); } });
If your "button" is a button
element, make sure you explicity set the type
attribute, otherwise the WebForm will treat it as submit by default. 如果您的“按钮”是一个
button
元素,请确保明确设置type
属性,否则WebForm会默认将其视为提交。
<button id="dealSaveBtn" type="button">Go</button>
If it's an input
element, try below : 如果它是
input
元素,请尝试以下操作:
e.preventDefault();
Read more: event.preventDefault() 阅读更多: event.preventDefault()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.