asp.net mvc为什么刷新页面后ajax响应

时间:2018-10-01 23:47:35

标签: c# jquery ajax asp.net-mvc-4

这种方法我正在编写数据库和文件夹操作。没问题 响应即将到来,但页面会刷新。取消文件夹操作后,问题消失了。我不希望页面刷新

 $(".btnSave").on("click", function (e) {

    var model = {
        "ProductName": productName, "BrandCategoryId": BrandCategoryId, "TaxRate": taxRate, "WareHouseId": WareHouseId, "ProductId": ProductId, "PurchasePrice": purchasePrice, "Count": count, "Discount": discount
    };
    e.preventDefault();
    e.stopPropagation();
    swal({
        title: "Lütfen Bekleyin", text: "Stok kayıt yapılıyor..", showConfirmButton: false, allowOutsideClick: false
    });
    $.ajax({
        method: "POST",
        url: "/Warehouseworker/JavaScript/NewStock",
        data: model,
        dataType: "json",
        success: function (response) {
            if (response.ModelErrors) {
                var errors = response.ModelErrors;
                swal.close();
                showErrors(errors);
            }
            if (response.errorMsg) {
                swal({ title: "Uyarı", text: "hata var", type: "warning" });
            }
            if (response.success) {
                swal({ title: "Stok kaydı gerçekleştirilmiştir", text: "", type: "success" });

            }

        }
    });
});

1 个答案:

答案 0 :(得分:0)

您是否正在使用按钮并且它处于表单形式?

如果是这样,请按下按钮type="button",它将不会刷新页面。默认行为是发布它所在的表单。

这是一个链接,然后添加href=javascript:;