reference jquery form plug-in, address: http://jquery.malsup.com/form/
<SCRIPT type = "text/JavaScript"> $ (function () {$ ("# btn_show "). BIND ("click", function () {$ ("# form_upload "). show (); var Options = {success: function (responsetext, statustext, xhr, $ form) {var picpath = responsetext. message; If (picpath = "") {alert (responsetext. message);} else {$ ("# form_upload "). hide (); alert (Unescape (responsetext. message. replace (// \/g, "%"); // $ ("# result "). ATTR ("src", picpath ). show () ;}, error: function (XMLHttpRequest, textstatus, errorthrown) {console. log (textstatus); console. log (errorthrown) ;}}; $ ("# form_upload "). ajaxform (options) ;}); </SCRIPT>
<Input type = "button" id = "btn_show" value = "Upload image"/> <br/>
<Form ID = "form_upload" style = "padding: 20px; display: none" Action = "addpic" method = "Post" enctype = "multipart/form-Data">
<Input name = "upimg" style = "width: 350px; Height: 25px;" size = "38" type = "file"/>
<Input type = "Submit" value = "Upload"/>
</Form>
Background C #Code:
[Httppost] public jsonresult addpic (httppostedfilebase upimg) {string filename = path. getfilename (upimg. filename); string filephysicalpath = server. mappath ("~ /Upload/"+ filename); string test =" \ u56fe \ u7247 \ u4ea0 \ u4f20 \ u6210 \ u529f "; string name =" ", message = ""; byte [] bytes = new byte [] {}; try {upimg. saveas (filephysicalpath); name = path. getfilename (filename); bytes = encoding. unicode. getbytes ("image added successfully"); For (INT I = 0; I <bytes. length; I + = 2) {message + = "\ U" + bytes [I + 1]. tostring ("X "). padleft (2, '0') + bytes [I]. tostring ("X "). padright (2, '0') ;}} catch (exception ex) {message = ex. message;} return JSON (New {name = Name, message = message });}
The background converts Chinese to Unicode code. After transmission, the JS script converts Unicode to Chinese and then displays it in the browser through a pop-up box.