Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ajax post Uncaught RangeError: Maximum call stack size exceeded

I have a problem with jQuery ajax. I have javascript

 <script type="text/javascript">
    $(function() {
        $('body').on("click", "#pager a", function(e) {
            e.stopPropagation();
            e.preventDefault();
            var a = $(this);
            var model = $('#searchForm').serialize();
            $.ajax({
                url: '/Product/Products',
                type: 'POST',
                data: {
                    model: model, page: a
                },
                success: function (data) {
                    alert('success');
                    $('#productsList').html(data);
                }
            });
        });
    });
</script>

This code produce error "Uncaught RangeError: Maximum call stack size exceeded" and I don't understand why. I have no trigger, I used preventDefault and stopPropagation, but I still have this error. Can anyone help me?

like image 732
user3609841 Avatar asked Jun 17 '16 13:06

user3609841


People also ask

How do you solve uncaught RangeError maximum call stack size exceeded?

The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created.

What is maximum call stack size exceeded?

The JavaScript exception "too much recursion" or "Maximum call stack size exceeded" occurs when there are too many function calls, or a function is missing a base case.


3 Answers

This error can also come if you are passing something in data which is not defined in that scope. Another reason is passing in data with val() directly.

like image 51
Gaurav Tyagi Avatar answered Oct 06 '22 10:10

Gaurav Tyagi


Instead of using var a = $(this) to get the page, use one hidden field and give page value to the field.

<input type="hidden" value="xyzpage" id="pageValue">

var pageVal = $("#pageValue").val();

data: {
         model: model, page:pageVal 
      },

This will solve the issue I guess

like image 36
Akhil Menon Avatar answered Oct 06 '22 10:10

Akhil Menon


You need to take off the var a = $(this);. I don't know what you try to achieve there but using a the jQuery wrapped clicked element as request data is a non-sense.

like image 2
Ivan Gabriele Avatar answered Oct 06 '22 11:10

Ivan Gabriele