Error uncaught exception out of memory in Ajax Process

0 votes

 I am submitting a simple form that has a small data and when I checked in the console tab the URL of ajax seems to be working but after the ajax was processed it will alert an error and it is redirected to my homepage and from the console tab I have this error:

Uncaught exception: out of memory

In my ajax I have this simple code only:

$("#add-comment").on('click', function() {

    var id = $('input[name=\'review_id\']').val();
    var customer_id = $('input[name=\'customer_id\']').val();
    var $comment = $('textarea[name=\'user_comment\']').val();

    var sample = "test";

    $.ajax({
        url: 'index.php?route=product/product/writeSubComment',
        type: 'post',
        dataType: 'json',
        data: { text: sample },
        beforeSend: function() {

        },
        success: function(data) {
            console.log(data.test);
        },
        error: function() {
            alert('ERROR!!!');
        }
    });

});

In my PHP controller I have this function

public function writeSubComment() {

    $json = array();

    $json['test'] = $this->request->post['text'];

    $this->response->addHeader('Content-Type: application/json');
    $this->response->setOutput(json_encode($json));

}

How to solve this error?

Jun 16, 2020 in PHP by kartik
• 37,510 points
1,469 views

1 answer to this question.

0 votes

Hello @kartik,

From your description of being redirected to your homepage, but having no code in your ajax response sections to do this, I suspect that the element #add-comment is a submit button in your form.

If this is the case, then your form may be submitting at the same time the ajax code is running when you click the #add-comment submit button. This would explain the out of memory error as the ajax javascript is being expunged while the page redirects.

You would need to prevent your form from submitting, and let the success() or failure sections handle the next step .

 One way to do this would be to change

$("#add-comment").on('click', function() {
     ... 

to

$('#add-comment').on('click', function(event){ 
    event.preventDefault();
    ...

or change the submit button from

<button type="submit" ...>Add comment</button>

to

<button type="button" ...>Add comment</button>

or change the form tag like this

<form onsubmit="return false;">

Hope this works!

answered Jun 16, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
1 answer

Error: Maximum execution time of 60 seconds exceeded in C:\xampp\phpmyadmin\libraries\dbi\mysql.dbi.lib.php on line 140

Hello @kartik, Go to: xampp\phpMyAdmin\libraries\config.default.php Look for : $cfg['ExecTimeLimit'] = 600; You ...READ MORE

answered Sep 1, 2020 in PHP by Niroj
• 82,880 points
13,860 views
0 votes
1 answer

Error:PHP Warning: POST Content-Length of 8978294 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

Hello @kartik, 8388608 bytes is 8M, the default ...READ MORE

answered Sep 17, 2020 in PHP by Niroj
• 82,880 points
27,510 views
0 votes
1 answer

Error:Trying to get property of non-object in C:\wamp\www\ni\pages\init.php..

Hello, Try mysql_fetch_object(). It returns an object, not an ...READ MORE

answered Nov 19, 2020 in PHP by Niroj
• 82,880 points
4,461 views
0 votes
1 answer

How do I strip all spaces out of a string in PHP?

If I have understood your question right, ...READ MORE

answered Feb 23, 2022 in PHP by Aditya
• 7,680 points
925 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,880 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,682 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,543 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,732 views
0 votes
1 answer

Error:Jquery - Uncaught TypeError: Cannot use 'in' operator to search for '324' in

Hello @kartik, You have a JSON string, not ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,880 points
6,433 views
0 votes
1 answer

How to post the parameter in ajax call of jquery datatable?

Hello @kartik, Just pass it like a normal ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,880 points
17,406 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP