A pseudo Ajax picture upload code implementation Example _ajax related

Source: Internet
Author: User
Copy Code code as follows:

<?php
if ($_files) {
?>
<script>
Window.parent.ajaxUploadPicture.uploadCallback (' yun_qi_img/5099213b07eca8065380ce7f75e95dda144ad348269.jpg ');
</script>
<?php
Die
}
?>
<! DOCTYPE html>
<script>


Ajaxuploadpicture = {$o 1: '};


Ajaxuploadpicture.ajaxuploadfile = function ($o) {
this. $o 1 = $o;
var $iframe = document.createelement (' iframe ');
$iframe. style.display = ' None ';
$iframe. Name = ' iframe ';
$iframe. id = ' iframe ';
Document.body.appendChild ($iframe);


var $form = document.createelement ("form");
$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 = "200";
$pic. Height = "150";
$pic. src = $url;

if (document.getElementById (' picshow ') = null) {
$div = document.createelement ("div");
$div. id = ' Picshow ';
this. $o 1.parentnode.insertbefore ($div, this. $o 1.nextSibling);
}else{
$div = document.getElementById (' picshow ');
}
$div. InnerHTML = ';
$div. appendchild ($pic);
};
</script>
<body>
<input type= "File" name= "file" onchange = "ajaxuploadpicture.ajaxuploadfile (this);" >
</body>

Object oriented thinking, form submits to a hidden IFrame, executes the callback JS function. Implement a picture echo. The function of the backstage PHP is not perfect.
Related Article

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.