【问题标题】:How to Send file field using jquery ajax?如何使用 jquery ajax 发送文件字段?
【发布时间】:2012-08-06 12:22:12
【问题描述】:
$.ajax({
        url: 'index.php?route=account/edit',
        type: 'post',
        data: $('#account_edit input[type=\'text\'], #account_edit input[type=\'password\'],**#account_edit input[type=\'file\']**,#account_edit input[type=\'radio\']:checked'),
        dataType: 'json',
        beforeSend: function() {
            $('#button-update').attr('disabled', true);
            $('#button-update').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
        },  
        complete: function() {
            $('#button-update').attr('disabled', false); 
            $('.wait').remove();
        },          
        success: function(json) {
            $('.warning').remove();
            $('.error').remove();
            //alert(json['error']['firstname']);

            if (json['redirect']) {
                //location = json['redirect'];
            }

}

【问题讨论】:

标签: jquery ajax json


【解决方案1】:

我使用jQuery form plugin 以类似ajax 的方式提交文件,特别是.ajaxSubmit() 方法。

【讨论】:

    【解决方案2】:

    $.ajax() 不支持文件上传。最好试试ajaxForm之类的插件来上传文件。

    【讨论】:

      猜你喜欢
      • 2018-10-17
      • 2011-08-08
      • 1970-01-01
      • 2019-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多