Ajaxfileupload. js compatibility issues, ajaxfileupload. js

Source: Internet
Author: User

Ajaxfileupload. js compatibility issues, ajaxfileupload. js
Question 1: ajaxfileupload returns the json<pre>

Problem description:

The file is submitted normally, the background receives the file normally, and the json returned in the action is normal. use Firefox to view the file, and the response value is normal.

However, in ajax calling js, success is not used.

After investigation, the returned json contains<pre>Label.

Solution:

Ajaxfileupload. js file, in uploadHttpData

Eval ("data =" + data); changed to data = jQuery. parseJSON (jQuery (data). text ());

Problem 2: the value of the IE and Chrome Text Selection boxes is lost.

Problem description:
After the foreground selects an image, the onchange event calls the ajaxfileupload method and performs image verification in the background. However, after the call, the value of the Text Selection box is lost. If ajaxfileupload is not called, the Text Selection box will display the image path (IE and Chrome have this problem, but Firefox is OK)

Solution:
Due to security concerns, in IE and chrome, jquery clone cannot clone the input field value, so the new input will lose the original value after cloning.
Add these four sentences after jQuery (form). submit ();. The principle is to copy the elements after submission.

     var oldElement = jQuery('#jUploadFile' +id ,form);     var newElement =  jQuery('#'+s.fileElementId );     jQuery(newElement).replaceWith(oldElement);     jQuery(oldElement).attr('id', s.fileElementId ); 

Question 3: the pop-up download box of the json returned by ie

Problem description:
Js works with the java springMVC background, and a message is returned after the request is successful. The chrom ff is normal and only the JSON returned after the IE is submitted will pop up the download box.

Solution:
View the type application/json after google found that the original IE does not support this identifier, so all are downloaded as files
There are generally three methods on the Internet:

  • First, manually specify response

  • Second, modify the configuration file (but I have always been a test success)

  • Third, stop using @ ResponseBody and use ResponseEntity instead.
    This method has the highest success rate, but it is difficult to modify it. If you have used @ ResponseBody in many places
    This instance also adopts the third method. The modified code is as follows:

@ RequestMapping ("/security/uploadPic") public ResponseEntity <Map <String, String> uploadPic (HttpServletRequest request, HttpServletResponse response) throws Exception {// set the response type to json and the response encoding to UTF-8 String itemId = request. getParameter ("itemId"); Map <String, String> retMap = null; String result = "success"; // retMap = fileUpload (request, itemId ); if (StringUtils. isNotEmpty (retMap. get ("reason") {result = "failure";} retMap. put ("result", result); logger.info ("uploadPic:" + retMap); HttpHeaders headers = new HttpHeaders (); headers. setContentType (MediaType. TEXT_PLAIN); return new ResponseEntity <Map <String, String> (retMap, headers, HttpStatus. OK );}

The above is a problem encountered when using ajaxfileupload. js. Record it. If you want to have other problems, contact me and add new problems and solutions to keep updating...
The reference documents are as follows:
Http://blog.csdn.net/ye1992/article/details/21178579
Http://bbs.csdn.net/topics/390910571
Http://www.bubuko.com/infodetail-374296.html

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.