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 ();
}
}
});