Tips for downloading data when returning JSON format in IE browser

Source: Internet
Author: User

Problem:

When the form is submitted asynchronously with Jquery.form.js, the data in JSON format is received, but it is strange to be prompted to download the file in IE, all the other browsers are normal, and after downloading, the contents are the data returned in the controller.

Solution :


Original return value set: Context. Response.ContentType = "Application/json";

Try: Context. Response.ContentType = "text/xml;"; Failed

Then I tried it: context. Response.ContentType = "Text/plain;charset=utf-8";


Example

Public ActionResult Shangchuanempphoto ()
{
Webimage pic = Getimagefromrequest ();
Webimage pic = new Webimage (request.inputstream);
int maxwidth = 600;
int maxheight = 400;
int minwidth = 160;
int minheight = 160;
if (pic!= null)
{
String imagename = Gettalentid ();
String imagename = MyClasses.KwstuLib.ClassesLib.GetIdByTime ();
String imageformat = pic. ImageFormat;
if (pic. Width > MaxWidth | | Pic. Height > MaxHeight) pic. Resize (MaxWidth, MaxHeight, True, true);
if (pic. Width < MinWidth | | Pic. Height < MinHeight) pic. Resize (MinWidth, MinHeight, True, false);
Pic. Save (Getuploadphotopath () + "temp\\" + imagename);
Touxianginfo Touxiang = new Touxianginfo ()
{
W_full = pic. Width,
H_full = pic. Height,
TempFileName = ImageName + "." + ImageFormat
};
Return Json (new
{
List = Touxiang
}, "text/html");
}
return Content ("0");
}


in view:


Upload Photos
$ (' #uploadfile '). Change (function () {
var filepath = $ ("#uploadfile"). Val ();
if (filepath = = "") return false;
var Extstart = Filepath.lastindexof (".");
var ext = filepath.substring (Extstart, Filepath.length). toUpperCase ();
if (ext!=). BMP "&& ext!=". PNG "&& ext!=". GIF "&& ext!=". JPG "&& ext!=". JPEG ") {
Alert ("Picture limited to bmp,png,gif,jpeg,jpg format");
return false;
}
$ (' #ShangChuanTuPianForm '). Submit ();
});
$ ("#ShangChuanTuPianForm"). Ajaxform ({
Beforesend:function () {
$ ("#shangchuan"). attr ("Disabled", "disabled"). Val ("uploading");
},
DataType: ' HTML ',//default is HTML type, does not write on Firefox has an impact
Cache:false,
Success:function (response) {
if (response!= "0") {
ResponseText = Json.parse (response); Convert HTML to JSON type
$.each (responsetext, function (index, item) {
$ ("#TuPianImg"). Append ("$ ("#tempfilename"). Val (Item.tempfilename);
$ ("#w_full"). Val (Item.w_full);
$ ("#h_full"). Val (Item.h_full);
});
$ ("#TempImage"). Jcrop ({
aspectratio:0.7692,
Aspectratio:1,
Setselect: [0, 0, 160, 160],
Onchange:changecropinfo
}, function () {
Jcropapi = this;
});
$ ("#ShangChuanTuPianKongJian"). Hide ();
$ ("#CaiJianTuPianKongJian"). Show ();
}
}
});

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.