uncaught exception: out of memory in Ajax Process

2021/01/30 10:41 · jquery ·  · 0评论

I got a problem 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 weird 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));

}

从您重定向到主页的描述,但是在ajax响应部分中没有执行此操作的代码,我怀疑元素#add-comment是表单中的提交按钮。

如果是这种情况,那么当您单击#add-comment提交按钮时,您的表单可能会在运行ajax代码的同时提交。这将解释页面重定向时ajax javascript被清除时的内存不足错误。

您将需要阻止表单提交,并让成功()或失败部分处理下一步(即刷新页面,更新评论框)。一种方法是更改

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

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

或从更改提交按钮

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

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

或像这样更改表单标签

<form onsubmit="return false;">

根据我现有的信息,这是我最好的猜测。

在Firefox中进行测试时,我遇到了类似的问题。更改按钮是typesubmitbutton为我工作。

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

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

当我尝试在HTML DOM中显示结果并解决以下问题时,在通过Ajax执行搜索时遇到了此错误:

$('..a place where the processed output Ajax request..').on('click', '#add-comment', function() {...});

我的问题通过改变而解决

<button onClick="save_order_info_into_database()">Save</button>

进入

<button type="button" onClick="save_order_info_into_database()">Save</button>

表示通过添加已type="button"解决的地雷。

本文地址:http://jquery.askforanswer.com/uncaught-exception-out-of-memory-in-ajax-process.html
文章标签: ,   ,   ,  
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!

文件下载

老薛主机终身7折优惠码boke112

上一篇:
下一篇:

评论已关闭!