c# - IE wants to download JSON result....MVC3 -
my mvc3 app uploads documents user our server. returning jsonresult display errors, if any:
[httppost] public jsonresult savedocument(documentmodel model, httppostedfilebase postedfile) { //my wonderful code return json(new { success = true, message="ok" }); } heres how submit request:
var issubmitting = false; var adddocumentoptions = { beforesubmit: beforeadddocumentsubmit, // pre-submit callback success: afterdocumentsubmit // post-submit callback }; $('#btncreatedocument').click(function (e) { e.preventdefault(); $('#diverror').html(''); if (!issubmitting) { $('#createdocform').submit(); } }); this javascript function runs when upload complete:
function afterdocumentsubmit(responsetext, statustext, xhr, $form) { if (responsetext.success) { //no errors } else { $('#diverror').html('error: ' + responsetext.message); } } in ff, chrome etc., javascript code runs fine, in ie, browser wants download json result text. download/open file dialog box shouldnt appear. how make ie not download json result , behave other browsers? thanks
i ran similar problem doing same in spring mvc on java. problem spring returning content-type of json result application/json, seems make ie want download it. can try changing content-type text/plain; ie won't prompt download file in case. suspect similar might happening here.
you try:
return json(new { success = true, message = "ok" }, "text/plain"); in response new problem: issue responsetext string. need convert javascript object. can this:
var response = json.parse(responsetext); if(response.success) { ... } most browsers support json.parse(). if you're having issues non-compliant browsers, can use json javascript library.
Comments
Post a Comment