Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 517617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:51:09+00:00 2026-05-13T07:51:09+00:00

I am calling a Page Method from JQuery as described here: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/ This is

  • 0

I am calling a Page Method from JQuery as described here: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

This is all working fine. During testing I came across an error when my response from the Web Method was too large:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

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

I have set a try/catch block within my method to no avail, it is happening outside my method (during JSON Serialization).

StackTrace looks like this:

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)

Update :
The global and page level catches won’t work for me (but will probably get the bounty at this point. Maintaining a global exception for something very specific to one page call seems like a poor design decision.) The point of me wanting to catch the exception is so I can trunkcate the text and still make a valid response to the javascript call.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:51:09+00:00Added an answer on May 13, 2026 at 7:51 am

    It might be a great effort, but if a well-designed solution is what you’re after, I’m thinking your best bet is probably to create a class that extends the service handler, that implements your own custom serializer, where you check for maxJsonLength. You could then setup your web.config to let all (or some) asmx requests be handled by your own handler. The Spring framework seems to facilitate this, although I haven’t looked closer into that solution.

    Be aware, though, that manually truncating a JSON string, without breaking the syntax, could be quite an effort in itself.

    Another solution, which would perhaps be easier to implement, and still arguably pretty neat, would be to overwrite (or wrap) jQuery’s $.ajax function with a function of your own, that stringifies the JSON on the client (this is done anyway, to create the request in the first place, so it shouldn’t be a lot of overhead), and checks length there. The gain with this approach is that you don’t have to mess with extending the service handler, but also, the part of truncating the object would be easier, as your javascript object is readliy at hand; you can iterate it, stringify subsets of it, check their length, or use wahtever mechanism you like, to implement smart truncating (obviously whatever means of truncating JSON you want to use, you’ll have to know your data, to be able to decide what can safely be removed without breaking key functionality in the request).

    If truncating cannot be done, you’d have the option of displaying an error message, without even having to hit the server.

    Since javascript is so flexible, you could specify, say, $.ajaxCore = $.ajax, and then overwrite $.ajax with your own function, that calls $.ajaxCore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I am calling a web service from jQuery using the .ajax method. The
I'm calling a classic .asp page from jquery to return a list (using JSONP).
I am facing an error when calling a WCF method from jQuery. The call
I'm trying to call an asp.net method using jquery/ajax from a button click on
Consider an ASP.NET page using the jQuery library Uploadify . Here is the sequence
I'm submitting a form silently i.e without page refresh using jquery.submit() method. When user
How would you access the cache from a jQuery ajax call? I'm using jquery
I am calling a Javascript function in my html page from a Flash movie
I am calling .ashx file for download excel file from Master page menu item.
I have an Employee class object that I am calling from my Login.aspx page's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.