In recent projects, the json data returned by uploading files will be prompted to download. This problem only occurs in IE10. The front-end uses the jQuery plug-in ajaxForm to submit the form, and the data format returned by the background is json. The code is as follows:
def jsonp(func):
"""Wraps JSONified output for JSONP requests."""
@wraps(func)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
temp_content = func(*args, **kwargs)
if isinstance(temp_content, dict):
temp_content.setdefault('success', True)
temp_content.setdefault('code', 200)
try:
temp_content = json.dumps(temp_content, indent=4)
except UnicodeDecodeError:
try:
temp_content = ujson.dumps(temp_content)
except StandardError as e:
Logger.exception(e)
temp_content = json.dumps({'success': False, 'code': 500, 'info': 'INVALID_CONTENT'})
temp_content = cgi.escape(temp_content)
if callback:
# Based on
http://evilcos.me/?p=425, jsonp adds /**/The head will be safer
content = '/**/' str(callback) '(' temp_content ')'
mimetype = 'application/javascript'
headers = {'charset':'utf-8'}
return current_app.response_class(content, mimetype=mimetype, headers=headers)
else:
mimetype = 'application/json'
headers = {'charset':'utf-8'}
content = temp_content
return current_app.response_class(content, mimetype=mimetype, headers=headers)
elif isinstance(temp_content, basestring):
temp_content = cgi.escape(temp_content)
return temp_content
else:
return temp_content
Return decorated_function
@mod.route('/patch/install.json', methods=['POST'])
@jsonp
def patch_install():
Return {'data': 'data'}
Note: The backend of this example uses Python. If you encounter the same problem in the project, change it to the corresponding language
To summarize, in fact, to solve this problem, simply put it in one sentence: "Change the data format returned by the backend to text/html format"