如何在ajax调用后停止页面重新加载? 我已经搜索了所有网络并且没有解决方案。我的表单是字符串格式,所以我不能使用Submit事件来阻止默认的事件处理程序。还有其他解决方案吗?
function ShopManageAddNewShopProduct() {
var options = "";
bootbox.dialog({
message: '<form id="formoidNew" name="formoidNew" >' +
'<div class="form-group col-sm-6" >' +
'<div id="ShopManageProductImageDiv">' +
'<p style="">تصویر محصول</p>' +
'<input id="ShopManageProductFileBrowsePicture" type="file" onchange="SetShopManageProductPicture(this)" style="float:right" class="myFile">' +
' <img id="ShopManageProductPicture" style="direction:ltr;float:left" width="100" height="100" />' +
'</div>' +
'</div><!--تصویر-->' +
'<input type="submit" id="btnsubmit" value="ثبت" />'+
'</form>',
title: "جديد",
onEscape: function () { },
backdrop: true,
size: "large",
buttons: {
Ok: {
label: "تاييد",
type: "submit",
className: "btn-success",
callback: function () {
ShopManageSubmitNew(event);
}
},
}
});
}
第二个功能是:
function ShopManageSubmitNew(e) {
var file_data = $('#ShopManageProductFileBrowsePicture').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: "/Shop/AddNewProduct",
type: 'POST',
cache: false,
contentType: false,
processData: false,
data: form_data,
success: function (data) {
}
},
complete: function(ee){
debugger;
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
}