AjaxFileUpload实现文件异步上传
<!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="http://www.phpddt.com/usr/themes/dddefault/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="ajaxfileupload.js"></script> </head> <script> jQuery(function(){ $("#buttonUpload").click(function(){ //加载图标 /* $("#loading").ajaxStart(function(){ $(this).show(); }).ajaxComplete(function(){ $(this).hide(); });*/ //上传文件 $.ajaxFileUpload({ url:'upload.php',//处理图片脚本 secureuri :false,fileElementId :'fileToUpload',//file控件id dataType : 'json',success : function (data,status){ if(typeof(data.error) != 'undefined'){ if(data.error != ''){ alert(data.error); }else{ alert(data.msg); } } },error: function(data,status,e){ alert(e); } }) return false; }) }) </script> <body> <input id="fileToUpload" type="file" size="20" name="fileToUpload" class="input"> <button id="buttonUpload">上传</button> </body> </html>
主要参数说明: 需要了解相关的错误提示 1,SyntaxError: missing ; before statement错误 2,SyntaxError: syntax error错误 3,SyntaxError: invalid property id错误 4,SyntaxError: missing } in XML expression错误 如果出现这个错误就需要检查文件域名称是否一致或不存在 5,其它自定义错误 大家可使用变量$error直接打印的方法检查各参数是否正确,比起上面这些无效的错误提示还是方便很多。(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |