如何让新FORMDATA()在IE浏览器工作 [英] how to make new FormData() work on IE browsers

查看:634
本文介绍了如何让新FORMDATA()在IE浏览器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能使这项工作在IE浏览器? 这不会在IE浏览器,新的FORMDATA()API不支持IE浏览器,是否有任何其他等同于新FORMDATA()在IE浏览器的API?

 变种FD =新FORMDATA();
fd.append(userfile的,$(#userfile的)[0] .files [0]);

$阿贾克斯({
    网址:/用户/ ajax_upload /',
    键入:POST,
    的contentType:假的,
    缓存:假的,
    数据:FD,
    过程数据:假的,
    beforeSend:函数(){
    },
    成功:功能(数据){
        $('#popupbox')的HTML(数据)。
    }
});
 

解决方案

其更好地使用jQuery的表单JS超过AJAX提交的图像。我发现它比 FORMDATA()

更好

 <脚本类型=文/ JavaScript的SRC =/ JS / jquery.form.js>< / SCRIPT>

功能update_professional_details(){
    VAR的选择= {
                网址:'/ validateform /个人,
                类型:$(#personal_edit_form)ATTR(方法),
                数据类型:JSON,
                成功:功能(数据){
                    VAR味精= data.msg;
                    如果(data.status =='成功'){
                        $(#msg_data)。HTML(更新成功后,重定向...)
                        $(#personal_edit_form)提交()。
                    }其他{
                        $('P [类$ =_误差2])HTML('')。
                        VAR味精= data.msg;
                        $每个(味精,功能(K,V){
                            $(+ K +_误差2''。')的HTML(v)中。;
                        });
                    }
                },
            };
            $('#personal_edit_form)ajaxSubmit会(选件)。
                返回false;
        }

    $('#updatepersonal)。点击(函数(){
        update_professional_details();
            返回false;
    });
 

How can I make this work on IE? This won't work on IE, new FormData() api is not supported by IE browsers, is there any other api equivalent to new FormData() in IE?

var fd = new FormData();
fd.append( "userfile", $("#userfile")[0].files[0]);

$.ajax({
    url : '/user/ajax_upload/',
    type: 'POST',
    contentType:false,
    cache: false,
    data: fd,
    processData: false,
    beforeSend :function(){
    },
    success : function( data ) {
        $('#popupbox').html(data);  
    }
});

解决方案

Its better to use jquery form Js for submitting images over ajax. I found it better than FormData()

<script type="text/javascript" src="/js/jquery.form.js"></script>

function update_professional_details(){
    var options = { 
                url     : '/validateform/personal',
                type    : $("#personal_edit_form").attr('method'),
                dataType: 'json',
                success:function( data ) {
                    var msg = data.msg;
                    if(data.status == 'success'){
                        $("#msg_data").html("Updated successfully, redirecting...")
                        $("#personal_edit_form").submit();
                    }else{
                        $('p[class$="_error2"]').html('');
                        var msg = data.msg;
                        $.each(msg, function(k, v) {
                            $('.'+k+'_error2').html(v);
                        });
                    }
                },
            }; 
            $('#personal_edit_form').ajaxSubmit(options);
                return false;
        }

    $('#updatepersonal').click(function(){
        update_professional_details();
            return false;
    });

这篇关于如何让新FORMDATA()在IE浏览器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆