简体   繁体   English

提交一份<input type="“file”">使用 jQuery $.post

[英]Submit an <input type=“file” /> using jQuery $.post

I have a <div/> tag which contains a file upload <input id="file" type="file"/> tag.我有一个<div/>标签,其中包含一个文件上传<input id="file" type="file"/>标签。 I want to post the contents of the input tag to a php page using $.ajax() or $.post() but how do I grab the contents of the input tag having its type as "file" ?我想使用$.ajax()$.post()input标签的内容发布到 php 页面,但是如何获取类型为"file"input标签的内容? so I can submit it using the jQuery ajax functions?所以我可以使用 jQuery ajax 函数提交它吗?

Note: My code doesn't have a <form/> tag yet.注意:我的代码还没有<form/>标签。 I am not sure if its mandatory to upload files.我不确定它是否强制上传文件。 Also i've seen some workarounds using <iframe> I want to know if this can be done otherwise.我还看到了一些使用<iframe>的解决方法,我想知道这是否可以通过其他方式完成。

I don't want to use any plugins to do this.我不想使用任何插件来做到这一点。

A byte stream can't be part of an asynchronous request.字节 stream 不能是异步请求的一部分。

In other words, you can't send data using AJAX approaches.换句话说,您不能使用 AJAX 方法发送数据。

you can't send file through $.post... you can use this link to uplaod file through ajax.. http://www.uploadify.com/demos/您不能通过 $.post 发送文件...您可以使用此链接通过 ajax.. http://www.uploadify.com/demos/上传文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM