繁体   English   中英

防止通过ajax发送表单数据时页面重新加载

[英]prevent page reload on sending formdata by ajax

在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);
            }
        });
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM