weixin_33725270 2015-11-03 13:37 采纳率: 0%
浏览 54

Ajax通过Ajax提交表单

I have a working form which uses FormData. I have now realised that this does not work in IE8 or IE9. Therefore, I am trying to create an alternative submit for these browsers. So in my submitHandler, I have the following

submitHandler: function (form) {
    if(typeof window.FormData === 'undefined' ){
        ie_ajax_upload();
    }
    else {
        //normal form submit
    }
}

So if the browser does not support FormData I call the function ie_ajax_upload. At the moment, this function looks like the following

function ie_ajax_upload(){
    var iframe = $('<iframe name="postiframe" id="postiframe" style="display: none"></iframe>');

    $("body").append(iframe);

    var form = $('#my-form');
    form.attr("action", "php/process.php");
    form.attr("method", "post");

    form.attr("encoding", "multipart/form-data");
    form.attr("enctype", "multipart/form-data");

    form.attr("target", "postiframe");
    form.attr("file", $('#fileOne').val());
    form.submit();

    return false;
}

fileOne is the id of my file field in my form. At the moment, with the above, the function is successfully called. However, IE8 is giving the error

Unable to get property '0' of undefined or null reference

In relation to form.submit();

Why would this be occurring?

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改