Javascript-ajax: $ _ files accepted for uploading files to the background is blank

Source: Internet
Author: User
Javascript code: {code...} background code: {code...} the returned data is [] javascript code:


  

Script var up = function (o, success, x, file) {if (typeof success = 'function') file = o; x = new XMLHttpRequest () x. open ('post', 'http: // 127.0.0.1/up. php? R = '+ Math. random (), 1) x. onload = function (r) {r = x. responseText if (success) // if r. pid and the twice parameter existing return success (r)} x. send (file)} script, script, img. onchange = function () {if (! This. files |! This. files [0]) return alert ('an error occurred while selecting the file! ') Var imgfile = this. files [0] if (imgfile. type. indexOf ('image ')! = 0) return alert ('this is not an image or audio! ') Up (imgfile, function (r) {text. innerHTML = r})} script

Background code:

   
     

The returned data is []

Reply content:

Javascript code:


  

Script var up = function (o, success, x, file) {if (typeof success = 'function') file = o; x = new XMLHttpRequest () x. open ('post', 'http: // 127.0.0.1/up. php? R = '+ Math. random (), 1) x. onload = function (r) {r = x. responseText if (success) // if r. pid and the twice parameter existing return success (r)} x. send (file)} script, script, img. onchange = function () {if (! This. files |! This. files [0]) return alert ('an error occurred while selecting the file! ') Var imgfile = this. files [0] if (imgfile. type. indexOf ('image ')! = 0) return alert ('this is not an image or audio! ') Up (imgfile, function (r) {text. innerHTML = r})} script

Background code:

   
     

The returned data is []

Upload files asynchronously. useFormData. For example:

var oMyForm = new FormData();oMyForm.append("file", file);x.send(oMyForm);

Reference: http://www.cnblogs.com/lhb25...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.