JQuery causes and solutions for the problem that files uploaded by IE9 cannot enter the background (ajaxfileupload. js fourth bullet)

Source: Internet
Author: User

JQuery causes and solutions for the problem that files uploaded by IE9 cannot enter the background (ajaxfileupload. js fourth bullet)
The cause of this problem is actually caused by function getFilePath (obj) {if (window. navigator. userAgent. indexOf ("MSIE")> = 1) {obj. select (); return document. selection. createRange (). text;} else if (window. navigator. userAgent. indexOf ("Firefox")> = 1) {if (obj. files) {return obj. files. item (0 ). getAsDataURL ();} return obj. value;} return obj. value ;}} this function was initially added for compatibility, but unfortunately it was self-defeating. This function was directly posted from the Internet. At that time, it was afraid that different browsers could not directly use the file name (). val. However, when using the IE browser, the document. selection. createRange (). text is a "" (empty string), so you can use obj directly. value or you do not need to use this method, directly through (). val () to get the file name. What surprised me is that using $ (). val () in IE can actually get the complete path of the file !!! Instead of just a file name, you don't have to upload the file before previewing. You can preview the image directly. This problem solved, re-run the code, the cause of this problem is that after the jQuery-1.4.2 plug-in, has removed the handleError method, and downloaded the demo of friends will find, the jQuery-2.0.3 plug-in is used in the demo. So just change the jQuery plug-in? No. Because jQuery-2.0.3 is used because the delegate method is supported only after the jQuery-1.7 version, but we can add the handleError method to the ajaxfileupload. js plug-in. Copy the following code to ajaxfileupload. js, handleError: function (s, xhr, status, e) {// If a local callback was specified, fire it if (s. error) {s. error. call (s. context | s, xhr, status, e);} // Fire the global callback if (s. global) {(s. context? JQuery (s. context): jQuery. event ). trigger ("ajaxError", [xhr, s, e]) ;}} solved the problem and re-run the Code. This is actually the focus of this article, open the browser and follow up on jQuery (form ). submit (); An exception is thrown here. This is the reason. For security reasons, you must click the <input type = 'file'> Control to upload a file. Because the length of <input type = 'file'> is really ugly and seldom meets our aesthetic requirements, we usually hide it and use other buttons to trigger it. This is not allowed in IE9. As for the solution, if you insist on using more beautiful upload controls, I think we should use some css techniques to block the <input type = 'file'> controls, this should be determined based on the actual situation. It is disgusting to say that Internet Explorer 9 breaks down the harmony of other browsers, and it is really confusing. For the previous demo, if <input type = 'file'> is displayed, the corresponding background must also be modified. The System is used to obtain the file name. web. httpContext. current. request. files [0]. change FileName to System. IO. path. getFileName (System. web. httpContext. current. request. files [0]. fileName) because the System. web. httpContext. current. request. files [0]. fileName is a complete file path, not just a file name. Of course, if we don't want to save the image to a local machine, we can preview it directly using the image path, but you must know that this is only suitable for IE ~~ Therefore, everyone considers it as appropriate.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.