robertosalemi Posted May 23, 2020 Report Posted May 23, 2020 (edited) Ciao a tutti,sto realizzando un'applicazione basata su ASP.net MVC.Tramite Ajax effettuo la chiamata ad diversi metodo, esempio può essere: public ActionResult MyMethod(DateTime ref_date) { try { //code return new FileContentResult(stream.ToArray(), "application/pdf"); } catch (Exception ex) { return StatusCode((int)HttpStatusCode.InternalServerError, ex.Message); } } Se l'eccezione non scatta, nella success della chiamata ajax eseguo la procedura desiderata...Se viene generata l'eccezione, scatta l'error della chiamata ajax, ma non riesco a catturare in alcun modo l'ex.Message: error: function (err, type, httpStatus) { console.log(err); var failureMessage = 'Error occurred in ajax call ' + err.status + " - " + err.responseText + " - " + httpStatus; console.log(failureMessage); console.log(err.responseText); } Se ad esempio il metodo va in eccezione perchè il file usato come modello è lockato da un altro processo, nell'eccezione del metodo lo vedo, nella chiamata Ajax no, non riesco a catturarlo.Probabilmente sbaglio il tipo di ritorno in caso di exception?Grazie. Edited May 23, 2020 by robertosalemi
robertosalemi Posted June 3, 2020 Author Report Posted June 3, 2020 Ho trovato l'errore, modificando questa parte della chiamata ajax: - se la risposta è success allora il type atteso è un blob - se la risposta è error allora il type atteso è un text xhr: function () { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 2) { if (xhr.status == 200) { xhr.responseType = "blob"; } else { xhr.responseType = "text"; } } }; return xhr; }, Grazie!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now