Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET WebMethod with jQuery json, is there a size limit?

Tags:

jquery

asp.net

I'm calling a webmethod using jquery, the webmethod returns a chunk of HTML that's then loaded into a div.

It works fine up until a certain size of chunk then it's doesn't work at all. It seems to stop working if the chunk of html is above 70KB.

The jQuery I'm using is:

 $(".letterBtn").live("click", function() {
    $("#divLoading").html('<img src="images/loading.gif" alt="Loading..." />');
    $.ajax({
        type: "POST",
        url: "Default.aspx/Search",
        data: "{sFor:" + "'" + this.id + "'" + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            $("#divOut").html(msg.d);
            $("#divLoading").html('');
        }
    });
});

The webmethod is similiar to this

  <WebMethod()> _ Public Shared Function Search(ByVal sFor As String) As String
    Dim htmlString As String = "<div>some html</div>"
    Return htmlString
End Function

I can't seem to figure out why it doesn't work for larger HTML chunks. Does anybody have any ideas? thanks!

like image 476
sooty Avatar asked Nov 14 '10 22:11

sooty


People also ask

Does WebMethod need to be static?

As we know, the property of a static method “We can invoke a static method using it's class name without creating an object of this specific class”. This is the reason it's necessary to declare WebMethod as a static method.

What is WebMethod in asp net?

The WebMethod attribute is added to each method we want to expose as a Web Service. ASP.NET makes it possible to map traditional methods to Web Service operations through the System. Web. Services. WebMethod attribute and it supports a number of properties that control the behavior of the methods.

How to use jQuery ajax in ASP net?

Client-Side - Using ajax() to Call Data Methods delegate('tr', 'click', function () { var req = $. ajax({ type: "POST", url: "AspAjax. aspx/GetUserDetails", contentType: "application/json; charset=utf-8", dataType: "json", data: "{ id: " + id + "}" }); req. done( /* Add function here to handle success case */ ); req.


1 Answers

found what I was after, the default setting seems to be 100k, I set the following in my web.config file. I think I'll rethink the html chunks now, it's doesn't seem like the best solution.

<webServices>
<jsonSerialization maxJsonLength="10000000"/>
</webServices>
like image 199
sooty Avatar answered Oct 08 '22 00:10

sooty