未捕获的异常:内存中的Ajax处理 [英] uncaught exception: out of memory in Ajax Process

查看:131
本文介绍了未捕获的异常:内存中的Ajax处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我提出,有一个小的数据一个简单的形式,当我在控制台设置页签阿贾克斯的URL似乎是工作,但后AJAX是处理它会提醒一个错误,它会被重定向到我的主页,并从控制台选项卡我有这样的奇怪的错误

  

未捕获的异常:内存不足

在我的AJAX我有这个简单的$ C $只有c:

  $(#附加注释)。在('点击',函数(){

    VAR ID = $('输入[名称= \'review_id \']')VAL()。
    VAR和客户id = $('输入[名称= \'CUSTOMER_ID \']')VAL()。
    变量$评论= $('textarea的[名称= \'user_comment \']')VAL()。

    VAR样本=测试;

    $阿贾克斯({
        网址:'index.php的路线=产品/产品/ writeSubComment',
        类型:'后',
        数据类型:JSON,
        数据:{文字:样品},
        beforeSend:函数(){

        },
        成功:功能(数据){
            执行console.log(data.test);
        },
        错误:函数(){
            警报(错误!);
        }
    });

});
 

在我的PHP控制器我有这个功能

 公共职能writeSubComment(){

    $ JSON =阵列();

    $ JSON ['测试'] = $这个 - >请求 - >后期['文本'];

    $这个 - >响应 - >和addHeader(内容类型:应用程序/ JSON);
    $这个 - >响应 - > setOutput(json_en code($ JSON));

}
 

解决方案

从你被重定向到您的主页,但有没有code在Ajax响应部分,以做到这一点的描述,我怀疑元素#add -comment是在你的表单提交按钮。

如果是这样的话,那么你的表格可提交在同一时间了ajax code运行时您单击#附加注释提交按钮。这可以解释了内存不足的错误作为Ajax的JavaScript被擦去,而页面重定向。

您需要prevent的形式从提交,而让成功的()或失败的部分处理下一步骤(即刷新页面,更新评论框)。这样做的一种方式是改变

  $(#附加注释)。在('点击',函数(){
     ...
 

  $('#附加注释)。在('点击',函数(事件){
    。事件preventDefault();
    ...
 

更改提交按钮

 <按钮类型=提交...>添加注释和LT; /按钮>
 

 <按钮式=按钮...>添加注释和LT; /按钮>
 

或改变形式标记像这样

 <形成的onsubmit =返回false;>
 

这是从我掌握的资料我最好的猜测。

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));

}

解决方案

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 (i.e. refreshing the page, updating the comments box). 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;">

This is my best guess from the information I have available.

这篇关于未捕获的异常:内存中的Ajax处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆