How to upload file using javascript?

This question already has an answer here: How can I upload files asynchronously? 27 answers Yes, it is possible, here's very simple code example : function upload() { var data = new FormData(), files = // some <input type="file" /> data.append('image', files[0]); $.ajax({ url: // Your ajax url, say it's upload.php, type: 'post', dataTy

如何使用JavaScript上传文件?

这个问题在这里已经有了答案: 我怎样才能异步上传文件? 27个答案 是的,这是可能的,这里有一个非常简单的代码示例: function upload() { var data = new FormData(), files = // some <input type="file" /> data.append('image', files[0]); $.ajax({ url: // Your ajax url, say it's upload.php, type: 'post', dataType: 'json', data: data,

jQuery:Sending pdf to server via ajax

This question already has an answer here: How can I upload files asynchronously? 27 answers There is good tutorial http://www.phpletter.com/DOWNLOAD/ read and understand it will help you. Anyways not my code but seems good way. function ajaxFileUpload(){ //starting setting some animation when the ajax starts and completes $("#loading") .ajaxStart(function(){ $(this).

jQuery:通过ajax发送pdf到服务器

这个问题在这里已经有了答案: 我怎样才能异步上传文件? 27个答案 有好的教程http://www.phpletter.com/DOWNLOAD/ 阅读并理解它会帮助你。 反正不是我的代码,但似乎很好的方式。 function ajaxFileUpload(){ //starting setting some animation when the ajax starts and completes $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this)

Upload file using ajax request

Possible Duplicate: How can I upload files asynchronously with JQuery? I'm submiting my forms like this. var url = event.currentTarget.action; var values = $(this).serialize(); $.post(url, values, function (data) { //some code }); Now I have a form with a file upload input. With this code the file isn't uploaded. How can I include the file into this ajax request ?

使用ajax请求上传文件

可能重复: 我怎样才能用JQuery异步上传文件? 我正在提交我的表格。 var url = event.currentTarget.action; var values = $(this).serialize(); $.post(url, values, function (data) { //some code }); 现在我有一个带有文件上传输入的表单。 使用此代码,文件不会被上传。 如何将文件包含到这个ajax请求中? 如果可能,我不想使用任何插件(jQuery除外)。 您只能使用AJAX上传文件,但只能在一些

Send input files data with ajax

This question already has an answer here: How can I upload files asynchronously? 27 answers Modern browsers that support the HTML5 file stuff have in the <input> element a "files" property. That will give you a file list reference, which has a length property. As the property is already an array so you just need to access it or iterate through it. JS var input = documen

用ajax发送输入文件数据

这个问题在这里已经有了答案: 我怎样才能异步上传文件? 27个答案 支持HTML5文件的现代浏览器在<input>元素中具有“files”属性。 这会给你一个文件列表引用,它有一个length属性。 由于该属性已经是一个array所以您只需要访问它或者遍历它。 JS var input = document.getElementById('id'); console.log(input.files); for (var i = 0; i < input.files.length; i++) { console.log(input.files[i]); }

Passing form data and file to php using ajax

This question already has an answer here: How can I upload files asynchronously? 27 answers Forms by default submit to wherever they're told. In order to stop this, you need to prevent it. Your js should look something like this: $("form#data").submit(function(event){ event.preventDefault(); ... }); change the submit type button to button type and then use AJAX like this: &l

使用ajax将表单数据和文件传递给php

这个问题在这里已经有了答案: 我怎样才能异步上传文件? 27个答案 默认情况下,表单会被提交到任何被告知的地方。 为了阻止这一点,你需要阻止它。 你的js应该是这样的: $("form#data").submit(function(event){ event.preventDefault(); ... }); 将submit类型按钮更改为button类型,然后像这样使用AJAX: <button type="button" name="btnSubmit" id="btnSubmit"> Submit </button> 您需要将j

Pass an image through AJAX

This question already has an answer here: How can I upload files asynchronously? 27 answers $.ajax({ type: "POST", url: pathname, data: new FormData($('#devis')[0]), processData: false, contentType: false, success: function (data) { $("#divider").html(data); } }); 并在$_FILES[];正常获取文件数据$_FILES[]; can you try it <script type="text/javascript">

通过AJAX传递图片

这个问题在这里已经有了答案: 我怎样才能异步上传文件? 27个答案 $.ajax({ type: "POST", url: pathname, data: new FormData($('#devis')[0]), processData: false, contentType: false, success: function (data) { $("#divider").html(data); } }); 并在$_FILES[];正常获取文件数据$_FILES[]; 你可以试试它 <script type="text/javascript"> $(document).ready(function()

Preview an image before it is uploaded

I want to be able to preview a file (image) before it is uploaded. The preview action should be executed all in the browser without using Ajax to upload the image. How can I do this? 请看下面的示例代码: function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#blah').attr('src', e.target.res

在上传之前预览图像

我希望能够在上传之前预览文件(图像)。 预览操作应该全部在浏览器中执行,而不使用Ajax来上传图像。 我怎样才能做到这一点? 请看下面的示例代码: function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#blah').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); }

data form content by ajax (no jquery)?

I am trying to send some form without reloading the page and I am trying to understand the under-the-hood details therefore not using any JavaScript library: var http = createRequestObject(); function createRequestObject() { var objAjax; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari objAjax=new XMLHttpRequest(); } else {// code for I

数据形式的内容由Ajax(没有jQuery)?

我试图发送一些表单而不重新加载页面,我试图理解下面的细节,因此不使用任何JavaScript库: var http = createRequestObject(); function createRequestObject() { var objAjax; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari objAjax=new XMLHttpRequest(); } else {// code for IE6, IE5 objAjax=new ActiveXObject("Microsoft.XMLHTTP"); }

Upload photo with Facebook Graph API and JavaScript: convert canvas image to multipart/form

From this SO question on the topic and from our research elsewhere on the web (like this Facebook doc link), it seems possible to upload an image from canvas.toDataURL() to Facebook directly -- without hosting the image on a server. The problem we're facing is how to convert the base64-encoded data from toDataURL() into the multipart/form-data that Facebook expects. Is this possible on the

使用Facebook Graph API和JavaScript上传照片:将canvas图像转换为multipart / form

从这个关于这个主题的问题以及我们在网络上其他地方的研究(如Facebook文档链接),似乎可以直接从canvas.toDataURL()上传图像到Facebook,而无需在服务器上托管图像。 我们面临的问题是如何将baseData编码的数据从toDataURL()转换为Facebook所期望的多部分/表单数据。 这是可能的JavaScript和jQuery.post()在客户端? 如果没有,我们可以求助于将图像保存在服务器上,但如果可能的话,宁愿绕过这一步骤,并从客户端做

Is it possible to perform an asynchronous cross

It is possible! Read below. First of all, let me use this diagram to explain how asynchronous file uploads can be achieved: Sorry. I've shut down one of my domains, and the image is gone now. It was a really nice image though. This was before I found out that Stack Overflow enables uploading images via Imgur. As you can see, the trick is to let the HTTP-response load into a hidden I

是否有可能执行异步交叉

有可能的! 参见下文。 首先,让我用这张图解释如何实现异步文件上传 : 抱歉。 我关闭了我的一个域,现在图像已经消失。 这是一个非常好的形象,但。 这是在我发现Stack Overflow允许通过Imgur上传图像之前。 正如你所看到的,诀窍是让HTTP响应加载到隐藏的IFRAME元素中,而不是页面本身。 (这是通过在使用JavaScript提交FORM时设置FORM元素的target属性来完成的。) 这工作。 但是,我面临的问题是服务器端脚本