doyz51819 2018-08-13 06:07
浏览 58
已采纳

JQuery fomdata将空数据发送到php文件?

I am trying to upload file through jquery formdata without any form. My problem is that it is not sending any data to php file.

Here is my jquery code

jQuery(document).ready(function() {
    jQuery('#e_picture').change(function() {

        var file_data = jQuery('#e_picture').prop('files')[0];
        var form_data = new FormData();
        form_data.append('e_picture', file_data);
        form_data.append('e_uid', '3585');

        //});
        // data: {e_uid: e_uid, e_picture:'23'},

        jQuery.ajax({
            url: "index.php?option=com_objectified&task=course_reg.addPicture",
            type: 'POST',
            data: {
                form_data
            },
            processData: false,
            contentType: false,
            success: function(result) {
                alert('This is ' + result); // Here I show onlu e_uid but it alerts blank result
            }
        });
    });
});

Html

<input type="file" class="form-control" name='e_picture' id='e_picture'>
  • 写回答

3条回答 默认 最新

  • dousidan1279 2018-08-13 06:26
    关注

    You are sending the form_data in wrong way

    instead of

    data: {
       form_data
    },
    

    just send it like

    data: form_data,
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试