Javascript 通过ajax上传文件的问题

Javascript 通过ajax上传文件的问题,javascript,jquery,ruby-on-rails,ruby-on-rails-3,carrierwave,Javascript,Jquery,Ruby On Rails,Ruby On Rails 3,Carrierwave,我试图通过ajax上传一个文件,但当我试图访问该文件时,出现以下错误: NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object 在jquery-min-on-line中: b = f.isFunction(b) ? b() : b, d[d.length] = encodeURIComponent(a) + "=" + encodeURIComponent(b) 以下是我的jq

我试图通过ajax上传一个文件,但当我试图访问该文件时,出现以下错误:

NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object
在jquery-min-on-line中:

 b = f.isFunction(b) ? b() : b, d[d.length] = encodeURIComponent(a) + "=" + encodeURIComponent(b)
以下是我的jquery代码:

$('#new_ar_bji_o_involved').submit( function(e){

    e.preventDefault();
    selectedid = $(this).attr('id');
    var report ={};
    report.authenticity_token = $(this).find('input[name=authenticity_token]').val();
    report.utf8 = $(this).find('input[name=utf8]').val()
    //$(this).serialize();
    report.other_involved = {};
    report.other_involved.ar_bail_juvinfo_id = $(this).find('#ar_bj_info_id').val();
    var d = document.getElementById('ar_bji_o_involved_mugshot');
    var B = d.files[0];
    report.other_involved.mugshot = B;

    $.ajax({
        type: "POST",
        url : "url?format=json",
        cache: false,
        data: report,
        contentType: "application/json",
        dataType: "json",
        success:function(data){
            //alert(data);
        },
        complete: function (data) {
             $("#dialog-message").dialog("open");
        }
    });     
}); 
我的表格

<form accept-charset="UTF-8" action="/crash_report/ar_save" class="changedateformat" enctype="multipart/form-data" id="new_ar_bji_o_involved" method="post">

<input id="ar_bji_o_involved_mugshot" name="ar_bji_o_involved[mugshot]" type="file">
</form>
也许你们可以从这里提出一些建议


提前感谢。

您不能通过AJAX发布多部分表单,因为Javascript无法访问您的文件系统


使用。它使ajax上传更加简单。

您不能通过ajax发布多部分表单,因为Javascript无法访问您的文件系统


使用。它使ajax上传更加简单。

非常感谢这个gem,我会查看它。非常感谢这个gem,我会查看它。
var d = document.getElementById('imgid');
A = new FormData();
var B = d.files[0];

A.append("contentType", "application/json");
                A.append("key", "b7ea18a4ecbda8e92203fa4968d10660");
A.append("employeeEvent[external_doc]", B);
A.append("employeeEvent[description]", $('#descriptionid').val());
A.append("employeeEvent[user_id]", $('#user_id').val());

var xhr = new XMLHttpRequest();
 xhr.open("POST", "/employee_management/add_event?format=json", true);   // <-- provide the proper URL

xhr.send(A);