A pseudo Ajax image upload code Implementation example

Source: Internet
Author: User

  This article mainly introduces their own write a pseudo Ajax image upload implementation code, need friends can refer to the following

  Code as follows: <?php  if ($_files) { ?>  <script>  Window.parent.ajaxUploadPicture.uploadCallback (' HTTP://IMG0.BDSTATIC.COM/IMG/IMAGE/5099213B07ECA8065380CE 7f75e95dda144ad348269.jpg ');  </script>  <?php  die; } ?>  <! DOCTYPE html>  <html>  <head>  <script>      ajaxuploadpicture = {$ O1: '};      ajaxuploadpicture.ajaxuploadfile = function ($o) {  this. $o 1 = $o;  var $iframe = do Cument.createelement (' iframe ');  $iframe. style.display = ' None ';  $iframe. Name = ' iframe ';  $iframe. Id = ' iframe ';  document.body.appendChild ($iframe);      var $form = document.createelement ("form"); nbsp $form. Method = "Post";  $form. enctype = "Multipart/form-data";  $form. Action = "";  $form. Target = ' iframe ';  $newO = $o. CloneNode ();  $form. appendchild ($newO);  $form. Submit (); }  AJaxuploadpicture.uploadcallback = function ($url) {    $pic = document.createelement (' img ');  $pic. Width = "; " $pic. Height = "; " $pic. src = $url;    if (document.getElementById (' picshow ') = null) {&N Bsp $div = document.createelement ("div");  $div. id = ' Picshow ';  this. $o 1.parentnode.insertbefore ($div, this.$ o1.nextsibling); }else{  $div = document.getElementById (' picshow '); }  $div. InnerHTML = ';   $div. appendchild ($pic); };  </script>  </head>  <body>  <input Type= "File" name= "file" onchange = "ajaxuploadpicture.ajaxuploadfile (this);" >  </body>  </html>    Object oriented thinking, form commits to a hidden IFrame, executes the callback JS function. Implement a picture echo. The function of the backstage PHP is not perfect.    
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.