1

我一直在尝试使用 ajax 提交文件$.post

var json_data = update_json_({name:first_name+' '+last_name,email:email,email2:email2,tele:tele,message:message,cc:$("#cc<?php echo $rand; ?>").val(),scauth:'<?php echo $auth_code; ?>'});     
$.post
(
    '<?php echo PATH_TO_PROCESSING_SCRIPT; ?>?r=<?php echo $rand; ?>&nocache=' + Math.floor(Math.random()*1000), json_data,
    function(data)
    {
        // place the returned data in the results div
        $("#results<?php echo $rand; ?>").html(data);
        // div#response is returned by send.php. if the submission was successful, div#response will have the class ui-state-highlight. otherwise, the submission failed. Hide the form on success.
        if($("#response").hasClass('ui-state-highlight'))
        {
            $('#c-form<?php echo $rand; ?>').hide('slow');
        }
    }
); //close $.post

这是将File对象附加到javascript object.

function update_json_(json_data)
{
    if(has_element("input[type=file]"))
    {
        var inputs = $("input[type=file]");
        fileobjs = [];
        for (var i = 0; i < inputs.length; i++)
        {
            fileobjs.push(inputs.eq(i).prop("files")[0]);
        }
        $.extend(json_data, { files : fileobjs } );
    }
    return json_data;
}

但目前,我在萤火虫中遇到错误。

NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object
[Break On This Error]   

...catch(c){return _.u}},stringify:function(f){function g(c){return h.call(this,c,a...
4

2 回答 2

1

您需要使用表单数据。. .

function update_json_(json_data)
{
    if(has_element("input[type=file]"))
    {
        var inputs = $("input[type=file]");
        fileobjs = [];
        for (var i = 0; i < inputs.length; i++)
        {
            fileobjs.push(inputs.eq(i).prop("files")[0]);
        }
        $.extend(json_data, { files : fileobjs } );
    }

    //add your files to form data. . 
    var fd = new FormData();    
    fd.append( 'files', fileobject );

    //similarly add your other data using fd.put('key', 'val');
    .
    . 

    //return data to be sent
    return fd;
}
于 2013-06-08T04:54:35.487 回答
0

我决定只使用malsup$.ajaxForm()的库

于 2013-06-12T06:02:31.833 回答