1

I have a jquery/ajax call to my web method defined in my C# code behind page in asp.net.

I am trying to return a string array of 2000 items.

I get an undefined error.

If the array is less than 400 it works OK.

So the problem is how I am returning large arrays to the jquery call.

I am returning from my web method this:

string[]

Is there a limit to the amount of items in an array i can return or do i have to parse it somehow to something json accepts?

New at this game so appreciate advice.

//client side

jQuery(function ($) {
    $.ajax({
        type: "POST",
        url: "Feed.aspx/PlayClips",
        data: JSON.stringify({
            ClipValue: lstMotionClips.options[lstMotionClips.selectedIndex].value,
            SessionID: sessionID,
            alias: alias
        }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {

            $.each(msg.d, function () {
                if (this['Text'] == "ERROR") {
                    alert(this['Value']);
                }
                else {

                    arrayresult = msg.d;
                    totalFrames = arrayresult.length;
                    PlayBack();
                }
            });    
        },
        error: function (msg) {
            alert(msg.d);}
    })
});

//server side

[WebMethod]
public static string[] PlayClips(string ClipValue, string SessionID, string alias)
{
    string[] frames = null;
    try
    {       
        string[] parentDirectory = Directory.GetDirectories(parentPath, guid, SearchOption.AllDirectories);
        if (parentDirectory.Length > 0)
        {
             frames = Directory.GetFiles(parentDirectory[0], "*.jpg", SearchOption.TopDirectoryOnly);
        }
    }
    catch (Exception _ex)
    {
        dalStatic.AddError("PlayClips." + _ex.ToString());
    }
    return frames;
}

Thanks

NB I have checked the total length of the string when the error starts.

It appears that a length of string up to 14188 is OK. As soon as I go beyond that I get the error. So, a threshold has been reached. I have set the MaxStringContent toa very high number but still get the error.

4
  • Might be worth showing your web service code/relevant config to determine where the issue lies Commented Jan 3, 2014 at 7:54
  • Can you make sure frames is not null when you get undefined error. Commented Jan 3, 2014 at 8:54
  • @Zaki Hi, thanks for your comment. I have already done that. Commented Jan 3, 2014 at 8:56
  • andrew see my answer. It will help you Commented Jan 3, 2014 at 9:02

1 Answer 1

2

Json have limits see here-->http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.maxjsonlength.aspx

change web.config somthing similarly

 <configuration>
... 
<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="XXXXXX" />
        </webServices>
    </scripting>
</system.web.extensions>
...

Sign up to request clarification or add additional context in comments.

2 Comments

hi, this was what I suspected and this was the answer I was hoping for. I am getting an error though when I put that in and I am trying to trace it as I type. ERROR: The configuration section 'system.web.extensions' cannot be read because it is missing a section declaration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.