Ajax数据添加与更新

前端之家收集整理的这篇文章主要介绍了Ajax数据添加与更新前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
var hotel = {
            UserName: '111111',Id: id,Name: $('#hotelName').val(),logo: img,BackgroundColor: $('#backgroundColor').val(),LangList: [{
                Active: $enlang,LangCode: 'en',Message: $('#Content-en').html()
            },{
                Active: $frlang,LangCode: 'fr',Message: $('#Content-fr').html()
            },{
                Active: $selang,LangCode: 'se',Message: $('#Content-se').html()
            }]
        };

        var _formData = new FormData();
        _formData.append("hotel",JSON.stringify(hotel));

        var path = $("#showimg").html();
        if (repath.length != 0 || id == null) {
            _formData.append('ImagePath',document.getElementById("txtImagePath").files[0]);
        }

        var $url = null;
        if (id == null) {
            $url = _url;
        } else {
            $url = _url + "/" + id;
        }

        $.ajax({
            url: $url,type: 'POST',cache: false,data: _formData,processData: false,contentType: false
        }).done(function (res) {
            window.location.reload();
            console.log('success,' + res);
        }).fail(function (res) {
            console.log('fail,' + res);
        });
    });
原文链接:https://www.f2er.com/ajax/160307.html

猜你在找的Ajax相关文章