Error: “Maximum call stack size exceed” AJAX calling WebMethod

2 posts, 0 answers
  1. Bill
    Bill avatar
    1 posts
    Member since:
    Jul 2016

    Posted 05 Jul Link to this post

    I'm trying to send a GridDataItem object that's retrieved from the selected row of a RadGrid.
    But I'm getting an Uncaught RangeError: Maximum call stack size exceeded error when I make this AJAX call.

    When I run the code, my AJAX success fires, but the breakpoint I have on the WebMethod never hits. After this, the pages freezes momentarily, then I get the error I mentioned above.

        $(document).ready(function () {
            $('#<%=btnTransferIn.ClientID%>').on('click', function () {
                var grid = $find("<%= gridStudents.ClientID %>"); //Returns an Object
                var gridSelItems = grid.get_selectedItems(); //Returns Array
                var selectedItem = gridSelItems[0]; //Returns an Object

                AjaxTransfer(gridSelItems);
            });
        });

        function AjaxTransfer(selectedItem) {
            $.ajax({
                type: "POST",
                url: "GradeSheet2.aspx/btnTransferIn_Click",
                data: { 'gsi': selectedItem },
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: alert('Complete')
            })
        }

    This is the WebMethod I want to call:

        [System.Web.Services.WebMethod]
        public static string btnTransferIn_Click(GridDataItem gsi)
        {
            return "Done";
        }

    I noticed, if I change the WebMethod's parameter to a string and I pass in a string instead of an object, it works.  So it seems like there's something wrong with the object or the way I'm passing it to the WebMethod.

    I checked the object in the console before I make the AJAX call and I think it looks alright.. Although, I don't have a high understanding of all of it.

    http://i.stack.imgur.com/TUv8C.png

    Please let me know if more information is needed.  

    Thanks in advance! 

  2. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 06 Jul Link to this post

    Hi Bill,

    You could run it in IE/Edge in debug mode to see exactly where the exception is happening.

    It is most probably because of selectedItem is object that have ._owner property. The _owner is Grid object which have items property that contain the item. So in general you can not pass the item as object inside your query.

    If you need to send the data key for this item, you could add the field into ClientDataKeyNames property of the grid.
    Then you could do 

    data: { 'gsi': selectedItem._data.yourField }

    Or if you want to sent the index:
    data: { 'gsi': selectedItem._itemIndex } 
    or
    data: { 'gsi': selectedItem._itemIndexHierarchical }


    Regards,
    Vasil
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top