【问题标题】:multipart/form-data not going in this ajax headermultipart/form-data 不在此 ajax 标头中
【发布时间】:2014-01-28 08:49:19
【问题描述】:
 <script type='text/javascript'>
   $(document).ready(function(){
    $('#send_message').click(function(e){

        var email = $('#email').val();   

        if(fname.length == 0){
            var error = true;
            $('#fname_error').fadeIn(500);
        }else{
            $('#fname_error').fadeOut(500);
        }

        if(error == false){
           $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });

          $.post("sub_register.php", $("#contact_form").serialize(),function(result){
               if(result == 'sent'){
                    $('#cf_submit_p').remove();

                    $('#mail_success').fadeIn(500);
                }else{
                    //show the mail failed div
                    $('#mail_fail').fadeIn(500);
                    //reenable the submit button by removing attribute disabled and change the text back to Send The Message
                    $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
                }
            });
        }
    });    
});

这是我的表单的标题。 我正在以这种形式使用文件上传。除上传的文件名外,所有其他表单元素数据都将进入我的提交页面。当我从我的页面中删除这个脚本并使用简单的表单提交时,它会发送上传的文件名。

如何在这个 ajax 标头中发送“multipart/form-data”。

提前致谢

【问题讨论】:

标签: php ajax forms header form-submit


【解决方案1】:

您不能通过 $.post 上传文件。相反,您可以使用Jquery Form plugin

这样,您的代码将如下所示:

    $("#contact_form").ajaxForm(function() { 
    if(result == 'sent'){
                $('#cf_submit_p').remove();

                $('#mail_success').fadeIn(500);
            }else{
                //show the mail failed div
                $('#mail_fail').fadeIn(500);
                $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
            }
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-31
    • 2014-06-11
    • 2019-02-26
    • 1970-01-01
    相关资源
    最近更新 更多