jq的ajax完整版本

$(function () {
    fileChange();
});
function fileChange() {
    $('#fileinput').change(function () {
        ajaxUploadImg();
    });
}

function ajaxUploadImg() {
    var formData = new FormData($('#idcardA')[0]);
    $.ajax({
        url: appObj.baseApiUrl + '/userinfo/UploadIDCardInfo',  //server script to process data
        type: 'POST',
        datatype: 'json',
        contentType: false,
        xhr: function () {  // custom xhr
            myXhr = $.ajaxSettings.xhr();
            if (myXhr.upload) { // check if upload property exists
                myXhr.upload.addEventListener('progress', progressHandlingFunction, false); // for handling the progress of the upload
            }
            return myXhr;
        },
        //Ajax事件
        //beforeSend: beforeSendHandler,
        success: function (data) {
            $('#idCardimg').attr('src', appObj.baseUrl + data);
        },
        error: function () {
            alert('error');
        },
        // Form数据
        data: formData,
        //Options to tell JQuery not to process data or worry about content-type
        cache: false,
        processData: false
    });
}

 

 

 

上传身份证正面照片:
                    <form />
                    </form>

 

相关文章:

  • 2022-12-23
  • 2021-12-07
  • 2021-08-14
  • 2021-12-16
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案