ajax files 空,javascript - $_POST and $_FILES empty after AJAX file upload - Stack Overflow

博主是一名初涉Web开发的学习者,在尝试使用Ajax进行文件上传时遇到了问题。当点击按钮后,前端通过jQuery的Ajax方法发送包含文件的FormData对象到handler.php,但后端收到的$_POST和$_FILES数组都是空的。尽管Chrome开发者工具显示请求负载中包含了文件信息。博主怀疑可能是对文件上传的理解有误,并寻求解答或相关资源以解决这个问题。
摘要由CSDN通过智能技术生成

I am new to web development, and the latest problem I have been having is ajax file uploading...

Right now I have two HTML input fields; a file input and a button.

After the button is clicked I then call a function that has the following code..

var frame = document.getElementById('Frame_');

var frameImg = frame.files[0];

var form_data = new FormData();

form_data.append('frame', frameImg);

jQuery.ajax({

url : './handler.php',

type : 'post',

data : form_data

contentType : false,

processData : false,

success : alert("Frame Uploaded")

});

When I var_dump() the $_POST and $_FILES array it shows both arrays as empty. This is despite the "Request Payload" in Chrome Dev reading

Content-Disposition: form-data; name="frame"; filename="GoldFrame.jpg"

Content-Type: image/jpeg

In which I am under the impression that this means the information of the file that I select on the front end is being successfully "post"ed to my handler.php file. Is this a wrong interpretation?

Either way, could someone please give me an answer to my problem? Or atleast point to a resource that might have my answer? There seem to be many similar questions along the same lines, but I haven't seen one that has a solid answer.

I have used iframes for this kind of thing in the past, but that seems like a really hacky method, and I would like to have the flexibility to use ajax for this kind of task in the future.

Help is appreciated.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值