AjaxSubmit solves the problem of successfully uploading and saving the json file. ajaxsubmitjson

Source: Internet
Author: User

AjaxSubmit solves the problem of successfully uploading and saving the json file. ajaxsubmitjson

The customer requested to upload the file and process the returned results in js. It was found that ajaxform is quite useful, and there was no problem in firefox testing,

However, the execution in IE browser prompts me to save the json file without using the success method. On the Internet, I have to set the type of the returned format to text/html, but I still cannot pass it.

Then I tried the latest version on the official website and introduced my latest js execution. The higher version is better, the compatibility is better, the BUG rate is low, and a js version is provided,

Convenient for everyone to download http://download.csdn.net/detail/hsliwei/7917853


JQueryformjs uses ajaxForm and ajaxSubmit to submit a form to upload a file. After the server returns json data, the IE browser cannot parse the file.

Forum.jquery.com/..-in-ie

Hi, I also encountered a problem when I used jQuery's ajaxSubmit for upload. I don't know how to solve it.

When the ajaxSubmit API submits a form, if a file is uploaded in the form, it determines whether the iframe parameter configured is set to false. If not, it creates a hidden iframe to submit the form, if iframe is set to false, you can determine whether the browser supports the HTML5 fileAPI. If the browser supports fileAPI, you can directly submit the file in XHR mode. Otherwise, the file is submitted as a normal form.
Therefore, because the form submitted by iframe is hidden, if the server returns "application/json" data, IE and Chrome download files by default, because the content is returned to iframe, instead of the success method of ajaxSubmit. After iframe loads the returned results, the success method of ajaxSubmit reads the iframe content and converts it to a json object.
The solution is to add a parameter in the configuration of the ajaxSubmit submission form, and the server determines whether the form is submitted by ajaxSubmit. If yes, the content of the "text/html" type is returned, if not, "application/json" is returned.
To put it simply, if ajaxSubmit uploads a file, the returned content can only be webpage content; otherwise, a download prompt box may appear in IE.
 

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.