﻿{"id":181,"date":"2016-05-04T22:13:27","date_gmt":"2016-05-04T14:13:27","guid":{"rendered":"http:\/\/www.chenweikang.top\/?p=181"},"modified":"2016-05-04T22:13:49","modified_gmt":"2016-05-04T14:13:49","slug":"ajaxfileupload%e6%8f%92%e4%bb%b6-%e5%bc%82%e6%ad%a5%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.chenweikang.top\/?p=181","title":{"rendered":"ajaxFileUpload\u63d2\u4ef6 \u5f02\u6b65\u4e0a\u4f20\u6587\u4ef6"},"content":{"rendered":"<h2>\u4e00\u3001ajaxFileUpload\u662f\u4e00\u4e2a\u5f02\u6b65\u4e0a\u4f20\u6587\u4ef6\u7684jQuery\u63d2\u4ef6\u3002<\/h2>\n<p>\u4f20\u4e00\u4e2a\u4e0d\u77e5\u9053\u4ec0\u4e48\u7248\u672c\u7684\u4e0a\u6765\uff0c\u4ee5\u540e\u4e0d\u7528\u5230\u5904\u627e\u4e86\u3002<\/p>\n<p>\u8bed\u6cd5\uff1a$.ajaxFileUpload([options])<\/p>\n<p>options\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<p>1\u3001url\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u00a0\u4e0a\u4f20\u5904\u7406\u7a0b\u5e8f\u5730\u5740\u3002<br \/>\n2\uff0cfileElementId\u3000\u3000\u3000\u3000\u3000 \u00a0\u9700\u8981\u4e0a\u4f20\u7684\u6587\u4ef6\u57df\u7684ID\uff0c\u5373&lt;input type=\"file\"&gt;\u7684ID\u3002<br \/>\n3\uff0csecureuri\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u662f\u5426\u542f\u7528\u5b89\u5168\u63d0\u4ea4\uff0c\u9ed8\u8ba4\u4e3afalse\u3002<br \/>\n4\uff0cdataType\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u3002\u53ef\u4ee5\u4e3axml,script,json,html\u3002\u5982\u679c\u4e0d\u586b\u5199\uff0cjQuery\u4f1a\u81ea\u52a8\u5224\u65ad\u3002<br \/>\n5\uff0csuccess\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u63d0\u4ea4\u6210\u529f\u540e\u81ea\u52a8\u6267\u884c\u7684\u5904\u7406\u51fd\u6570\uff0c\u53c2\u6570data\u5c31\u662f\u670d\u52a1\u5668\u8fd4\u56de\u7684\u6570\u636e\u3002<br \/>\n6\uff0cerror\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u63d0\u4ea4\u5931\u8d25\u81ea\u52a8\u6267\u884c\u7684\u5904\u7406\u51fd\u6570\u3002<br \/>\n7\uff0cdata \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u00a0\u81ea\u5b9a\u4e49\u53c2\u6570\u3002\u8fd9\u4e2a\u4e1c\u897f\u6bd4\u8f83\u6709\u7528\uff0c\u5f53\u6709\u6570\u636e\u662f\u4e0e\u4e0a\u4f20\u7684\u56fe\u7247\u76f8\u5173\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u4e1c\u897f\u5c31\u8981\u7528\u5230\u4e86\u3002<br \/>\n8, type \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u00a0\u5f53\u8981\u63d0\u4ea4\u81ea\u5b9a\u4e49\u53c2\u6570\u65f6\uff0c\u8fd9\u4e2a\u53c2\u6570\u8981\u8bbe\u7f6e\u6210post<\/p>\n<h2>\u9519\u8bef\u63d0\u793a:<\/h2>\n<p>1\uff0cSyntaxError: missing ; before statement\u9519\u8bef<br \/>\n\u5982\u679c\u51fa\u73b0\u8fd9\u4e2a\u9519\u8bef\u5c31\u9700\u8981\u68c0\u67e5url\u8def\u5f84\u662f\u5426\u53ef\u4ee5\u8bbf\u95ee<br \/>\n2\uff0cSyntaxError: syntax error\u9519\u8bef<br \/>\n\u5982\u679c\u51fa\u73b0\u8fd9\u4e2a\u9519\u8bef\u5c31\u9700\u8981\u68c0\u67e5\u5904\u7406\u63d0\u4ea4\u64cd\u4f5c\u7684\u670d\u52a1\u5668\u540e\u53f0\u5904\u7406\u7a0b\u5e8f\u662f\u5426\u5b58\u5728\u8bed\u6cd5\u9519\u8bef<br \/>\n3\uff0cSyntaxError: invalid property id\u9519\u8bef<br \/>\n\u5982\u679c\u51fa\u73b0\u8fd9\u4e2a\u9519\u8bef\u5c31\u9700\u8981\u68c0\u67e5\u6587\u672c\u57df\u5c5e\u6027ID\u662f\u5426\u5b58\u5728<br \/>\n4\uff0cSyntaxError: missing } in XML expression\u9519\u8bef<br \/>\n\u5982\u679c\u51fa\u73b0\u8fd9\u4e2a\u9519\u8bef\u5c31\u9700\u8981\u68c0\u67e5\u6587\u4ef6name\u662f\u5426\u4e00\u81f4\u6216\u4e0d\u5b58\u5728<br \/>\n5\uff0c\u5176\u5b83\u81ea\u5b9a\u4e49\u9519\u8bef<br \/>\n\u5927\u5bb6\u53ef\u4f7f\u7528\u53d8\u91cf$error\u76f4\u63a5\u6253\u5370\u7684\u65b9\u6cd5\u68c0\u67e5\u5404\u53c2\u6570\u662f\u5426\u6b63\u786e\uff0c\u6bd4\u8d77\u4e0a\u9762\u8fd9\u4e9b\u65e0\u6548\u7684\u9519\u8bef\u63d0\u793a\u8fd8\u662f\u65b9\u4fbf\u5f88\u591a\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u3000\u3000\u4f7f\u7528\u65b9\u6cd5\uff1a<\/h2>\n<h3>\u3000\u3000\u7b2c\u4e00\u6b65\uff1a\u5148\u5f15\u5165jQuery\u4e0eajaxFileUpload\u63d2\u4ef6\u3002\u6ce8\u610f\u5148\u540e\u987a\u5e8f\uff0c\u8fd9\u4e2a\u4e0d\u7528\u8bf4\u4e86\uff0c\u6240\u6709\u7684\u63d2\u4ef6\u90fd\u662f\u8fd9\u6837\u3002<\/h3>\n<div class=\"cnblogs_code\">\n<pre>    &lt;script src=\"jquery-1.7.1.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"ajaxfileupload.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;<\/pre>\n<\/div>\n<h3>\u3000\u3000\u7b2c\u4e8c\u6b65\uff1aHTML\u4ee3\u7801\uff1a<\/h3>\n<div class=\"cnblogs_code\">\n<pre>&lt;body&gt;\r\n    &lt;p&gt;&lt;input type=\"file\" id=\"file1\" name=\"file\" \/&gt;&lt;\/p&gt;\r\n    &lt;input type=\"button\" value=\"\u4e0a\u4f20\" \/&gt;\r\n    &lt;p&gt;&lt;img id=\"img1\" alt=\"\u4e0a\u4f20\u6210\u529f\u5566\" src=\"\" \/&gt;&lt;\/p&gt;\r\n&lt;\/body&gt;<\/pre>\n<\/div>\n<h3>\u3000\u3000\u7b2c\u4e09\u6b65\uff1aJS\u4ee3\u7801<\/h3>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>    &lt;script src=\"jquery-1.7.1.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"ajaxfileupload.js\" type=\"text\/javascript\"&gt;&lt;\/script&gt;\r\n    &lt;script type=\"text\/javascript\"&gt;\r\n        $(function () {\r\n            $(\":button\").click(function () {\r\n                ajaxFileUpload(); \/\/\u8c03\u7528 \u63d0\u4ea4\u5230\u670d\u52a1\u5668\r\n            })\r\n        })\r\n        function ajaxFileUpload() {\r\n            $.ajaxFileUpload\r\n            (\r\n                {\r\n                    url: '\/imgUpload.do', \/\/\u7528\u4e8e\u6587\u4ef6\u4e0a\u4f20\u7684\u670d\u52a1\u5668\u7aef\u8bf7\u6c42\u5730\u5740\r\n                    secureuri: false, \/\/\u662f\u5426\u9700\u8981\u5b89\u5168\u534f\u8bae\uff0c\u4e00\u822c\u8bbe\u7f6e\u4e3afalse\r\n                    fileElementId: 'file1', \/\/\u6587\u4ef6\u4e0a\u4f20\u57df\u7684ID\r\n                    dataType: 'json', \/\/\u8fd4\u56de\u503c\u7c7b\u578b \u4e00\u822c\u8bbe\u7f6e\u4e3ajson\r\n                    success: function (data, status)  \/\/\u670d\u52a1\u5668\u6210\u529f\u54cd\u5e94\u5904\u7406\u51fd\u6570\r\n                    {\r\n                        $(\"#img1\").attr(\"src\", data.imgurl);\r\n                        if (typeof (data.error) != 'undefined') {\r\n                            if (data.error != '') {\r\n                                alert(data.error);\r\n                            } else {\r\n                                alert(data.msg);\r\n                            }\r\n                        }\r\n                    },\r\n                    error: function (data, status, e)\/\/\u670d\u52a1\u5668\u54cd\u5e94\u5931\u8d25\u5904\u7406\u51fd\u6570\r\n                    {\r\n                        alert(e);\r\n                    }\r\n                }\r\n            )\r\n            return false;\r\n        }\r\n    &lt;\/script&gt;<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<h3>\u3000\u3000\u3000\u3000\u7b2c\u56db\u6b65\uff1a\u540e\u53f0\u9875\u9762imgUpload.do\u00a0\u4ee3\u7801 ( \u8fd9\u91cc\u4f7f\u7528SpringMvc\u5904\u7406\u63a5\u53d7\u7684\u6587\u4ef6 )\uff1a<\/h3>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img decoding=\"async\" src=\"http:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre>       \r\n@RequestMapping(\"imgUpload\")\r\n \r\n@ResponseBody\r\n \r\npublic String ImgUpload(@RequestParam(\"fileData\") CommonsMultipartFile fileData ,HttpServletRequest req) {\r\n \r\n \r\n        \/\/\u8fd9\u91cc\u5c31\u53ef\u4ee5\u4f7f\u7528fileData\u5bf9\u8c61\u5bf9\u6587\u4ef6\u8fdb\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\r\n        Sysotem.out.print(fileData.getName());\r\n         \r\n \r\n }<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #993300;\">*\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.chenweikang.top\">\u5de6\u624b\u4ee3\u7801\u53f3\u624b\u8bd7<\/a> &raquo; <a href=\"https:\/\/www.chenweikang.top\/?p=181\">ajaxFileUpload\u63d2\u4ef6 \u5f02\u6b65\u4e0a\u4f20\u6587\u4ef6<\/a><\/p><div class=\"__youshang\">\r\n            <div id=\"__youshang_popup\" class=\"wechat popup\" style=\"display: none;\">\r\n                <div class=\"head\">~\u8c22\u8c22\u6253\u8d4f~<\/div>\r\n                <div class=\"qrcode\"><div class=\"qrcode-li wechat\" ><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/wexin.png\" \/><\/div><div class=\"qrcode-li alipay\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-pay.png\" \/><\/div><div class=\"qrcode-li hongbao\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-hongbao.png\" \/><\/div><\/div>\r\n                <ul class=\"platform\"><li class=\"icon-wechat active\" data-bg-color=\"#05af4e\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-alipay \" data-bg-color=\"#00a2ea\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-hongbao \" data-bg-color=\"#dd5746\" data-thanks=\"<p>\u626b\u7801\u9886\u7ea2\u5305<\/p><p style='margin-top: 24px;'>\uff08\u4f59\u989d\u5b9d\u652f\u4ed8\u65f6\u53ef\u62b5\u73b0\uff09<\/p>\"><\/li><\/ul>\r\n            <\/div>\r\n            <a href=\"javascript:void(0);\" id=\"__youshang_btn\">\u8d4f<\/a>\r\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001ajaxFileUpload\u662f\u4e00\u4e2a\u5f02\u6b65\u4e0a\u4f20\u6587\u4ef6\u7684jQuery\u63d2\u4ef6\u3002 \u4f20\u4e00\u4e2a\u4e0d\u77e5\u9053\u4ec0\u4e48\u7248\u672c\u7684\u4e0a\u6765\uff0c\u4ee5\u540e\u4e0d\u7528\u5230 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[38],"class_list":["post-181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-note","tag-ajaxfileupload"],"_links":{"self":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=181"}],"version-history":[{"count":0,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/181\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/media\/137"}],"wp:attachment":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}