The example in this article describes the js method of cutting and scaling avatar images and uploading images without refreshing. Share it with everyone for your reference. The details are as follows:
fname: The name used when receiving in the background, required
funstr: function to start upload execution, default is None
funbak: callback function after successful upload, required
furl: upload address; default submission page of the current form
Note: The upload address and current address must be the same domain name, otherwise the callback function will not be able to obtain the address sent back after successful upload.
a.php:
$path='a.jpg'; move_uploaded_file($_FILES['uimg']['tmp_name'],$path); exit(json_encode(array('ztai'=>true,'url'=>$path)));
<form action="" method="get"> <input type="button" fname="uimg" funstr="function(){document.title='图片正在上传……';}" funbak="ddd" furl="a.php" value="本地上传"> </form> <script type="text/javascript"> function ddd(da){ if(da.ztai){ document.title='上传完成'; ui.success('上传成功保存地址为'+da.url); } } </script>
I hope this article will be helpful to everyone’s JavaScript programming design.