How to handle server-side exception during an Ajax call from jQuery?

I call the page method from jQuery as described here: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Everything is working fine. During testing, I encountered an error when my answer using the Web Method was too large: Error while serializing or deserializing using JSON JavaScriptSerializer. The string is longer than the value specified for the maxJsonLength property.

I was able to examine the maxJsonLength property a bit and set it higher, however I would like to try to catch this exception server before it is sent to the client during an Ajax call. How can I do it?

I set the try / catch block in my method to no avail, this happens outside my method (during JSON serialization).

StackTrace is as follows:

at System.Web.Script.Serialization.JavaScriptSerializer.Serialize (Object obj, StringBuilder output, SerializationFormat serializationFormat)  
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize (Object obj, SerializationFormat serializationFormat)  
at System.Web.Script.Services.RestHandler.InvokeMethod (HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)  
at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall (HttpContext context, WebServiceMethodData methodData)

:
(, , . - .) , - , - javascript.

+3
5

, - , , , - , , , , , maxJsonLength. web.config, ( ) asmx- . Spring framework, , , .

, , JSON, , .

, , , - , ( ) jQuery $.ajax , JSON ( , , ) . , , , javascript ; , , wahtever, , (, JSON, , , , ).

, , .

javascript , , , $.ajaxCore = $.ajax, $.ajax , $.ajaxCore.

+3

.

+2

.

+2

, . , . , , , (, - ).

, . MaxJsonLength , .

+1

, , , , ?

0

Source: https://habr.com/ru/post/1721735/


All Articles