<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><title>Untitled Document</title><Scripttype= "Text/javascript">window.onload=function(){ varFM=document.getElementsByTagName ("form")[0]; Fm.onsubmit=function() { //var Username=document.getelementbyid ("username"). Value; //var Password=document.getelementbyid ("password"). Value; //var Email=document.getelementbyid ("email"). Value; //var fmdata= "username=" +username+ "&password=" +password+ "&email=" +email; varFmdata=NewFORMDATA (FM); varXHR=NewXMLHttpRequest (); Xhr.onreadystatechange=function() { if(Xhr.readystate==4) {eval ("var obj="+xhr.responsetext); document.getElementById ("SCJG"). InnerHTML=OBJ.JG; if(Obj.name!=NULL) {document.getElementById ("SCTP"). InnerHTML=''+Obj.name+'\ "width=" height= "/> "';} }} xhr.open ("POST","/1.php"); //use Formdata without setting the table header //Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded");xhr.send (Fmdata); return false; } }</Script></Head><Body><DivID= "SCJG"></Div><DivID= "SCTP"></Div>Ajax+formdata+javascript Implementing a No-refresh form registration<formMethod= "POST">name<inputname= "username"type= "text"ID= "username"><BR>Password<inputname= "Password"type= "Password"ID= "Password"><BR>Email<inputname= "Email"type= "text"ID= "Email"><BR>file<inputname= "Nfile"type= "File"ID= "Nfile"><BR><inputtype= "Submit"value= "Submit"></form></Body></HTML>
<?PHP//Print_r ($_post);//print_r ($_files);$ary=Array();if($_files["Nfile"] ["Error"]>0){$ary[' JG ']= ' upload attachment is problematic, there may be no attachment '; EchoJson_encode ($ary);Exit();}$path= "./upfile/";$name=$_files["Nfile"] [' Name '];//Attachment uploadif(Move_uploaded_file($_files["Nfile"] [' Tmp_name '],Iconv("UTF-8", "GBK",$path.$name))){$ary[' JG ']= ' upload succeeded ';$ary[' Name ']=$path.$name;}Else{$ary[' JG ']= ' upload failed ';}EchoJson_encode ($ary);?>
Ajax+formdata+javascript implement no Refresh upload attachments