dongliantong3229 2015-11-20 12:59
浏览 46
已采纳

在firebug做一个ajax调用时得到“未捕获的异常:内存不足”

I've been trying to debug an ajax call with chrome and firefox. I'm newbie in both. When debbuging with chrome, I was getting an ajax response with the two last params (jqXHR, textStatus, errorThrown) empty and the first one was xhr status 0. I said sometimes, because I was getting some times an xhr status 200, and the params textStatus, errorThrown was printing parse error, and unexpected character '<'. I've been looking at my php code and this '<' is nowere because I've been doing a test: to comment every php code and to return the same $_POST['json'] that php is getting from the ajax call, and I was getting the same errors. I've been looking at my json and is well formed. Confused by all these errors and confusing debug tools that I don't understand very well, I moved to firefox and firebug, and there I get another diferent message: "uncaught exception: out of memory" I've been reading some others developers asking the same question, and tryed the accepted answers but I still can't find the issue, that's why I post my code here, hoping somebody can help. Thanks a lot!

html code:

                   <input type="submit" data-effect="mfp-zoom-out" value='Submit' onClick="setTypeAdvanced()" style= "
    position: relative;
    top: -152px;
    left: 129px;
" />

jscript code in index.js:

function setTypeAdvanced(){

    var advancedFormVars = {};
    /**SHOW*/

    if(document.getElementById('OfferID').checked == true){
        advancedFormVars['checkbox1'] = document.getElementById('OfferID').value;
    }
    if(document.getElementById('offerName').checked == true){
        advancedFormVars['checkbox2'] =document.getElementById('offerName').value;
    }
    if(document.getElementById('campaignID').checked == true){
        advancedFormVars['checkbox3'] = document.getElementById('campaignID').value;
    }
    if(document.getElementById('campaignName').checked == true){
        advancedFormVars['checkbox4'] = document.getElementById('campaignName').value;
    }
    if(document.getElementById('installs').checked == true){
        advancedFormVars['checkbox5'] = document.getElementById('installs').value;
    }
    if(document.getElementById('revenue').checked == true){
        advancedFormVars['checkbox6'] = document.getElementById('revenue').value;
    }


    /** FILTERS */
    if(document.getElementById('offerIDFilt').checked == true){
        advancedFormVars['checkbox7'] =  document.getElementById('offerIDFilt').value;
    }
    if(document.getElementById('publisherIDFilt').checked == true){
        advancedFormVars['checkbox8'] = document.getElementById('publisherIDFilt').value;
    }
    if(document.getElementById('publisherIDTextVal').value.length >'0'){
        advancedFormVars['checkbox9'] =  document.getElementById('publisherIDTextVal').value;
        publisherIDTextVal  =  document.getElementById('publisherIDTextVal').value;
    }
    if(document.getElementById('offIDTextVal').value.length > '0'){
        advancedFormVars['checkbox10'] =  document.getElementById('offIDTextVal').value;
    }

        /**GROUP BY*/
    if(document.getElementById('dates').checked == true){
        advancedFormVars['checkbox11'] = document.getElementById('dates').value;
    }
    if(document.getElementById('geos').checked == true){
        advancedFormVars['checkbox12'] = document.getElementById('geos').value;
    }
    if(document.getElementById('browsers').checked == true){//arreglar no coge checked, coge objeto html
        advancedFormVars['checkbox13']= document.getElementById('browsers').value;
    }
    if(document.getElementById('oS').checked == true){//arreglar coge undefined
        advancedFormVars['checkbox14'] = document.getElementById('oS').value;
    }





    /**ORDER BY*/
    if(document.getElementById('installsGroupBy').checked == true){
        advancedFormVars['checkbox15']= document.getElementById('installsGroupBy').value;
    }
    if(document.getElementById('revenueGroupBy').checked == true){
        advancedFormVars['checkbox16']= document.getElementById('revenueGroupBy').value;
    }

    advancedFormVars['none']= (typeof none=== 'undefined') ? 'default' : none;
    advancedFormVars['ASC']= (typeof ASC === 'undefined') ? 'default' : ASC;
    advancedFormVars['DESC']= (typeof DESC === 'undefined') ? 'default' : DESC;




    loadFormAdvanced(advancedFormVars);



}
function loadFormAdvanced(advancedFormVars){

    var json = JSON.stringify(advancedFormVars);

    $.ajax({
        url : 'AL_loadForm.php',
        type : 'POST',
        data : {
            json:json
        },
        dataType:'json',
        success : function(data) {
            alert(data);
        },
        error: function(jqXHR, textStatus, errorThrown) {
              alert('error '+errorThrown);
              alert('status '+textStatus);
              alert('xhr status '+jqXHR.status);
            }
    });
}

edit to add my php code:

<?php 
    if($_POST){ 
         if($_POST['json']){
              echo json_encode($_POST['json']); //also tryed echo($_POST['json']);
              } 
         }
?>

And this is my json:

{"checkbox1":"OfferID","checkbox2":"Offer Name","checkbox3":"CampaignID","checkbox4":"CampaignName","checkbox5":"Installs","checkbox6":"Revenue","checkbox7":"OfferID","checkbox8":"PublisherID","checkbox9":"some publisher","checkbox10":"some offer","checkbox12":"Geos","checkbox15":"Installs","none":"default","ASC":"default","DESC":"default"}

it has been copy/pasted from console log right before beeing sended in the ajax call:

var json = JSON.stringify(advancedFormVars);
console.log(json);
$.ajax({
    url : 'AL_loadForm.php',
    type : 'POST',
    data : {
        json:json
    },
    dataType:'json',
    success : function(data) {
        alert(data);
  • 写回答

1条回答 默认 最新

  • douliangbian7323 2015-11-20 13:50
    关注

    You are calling setTypeAdvanced without parameters upon clicking on your submit button. The function builds an object called advancedFormVars and calls loadFormAdvanced(advancedFormVars). After you stringify the variable, you are passing it to an AJAX POST request to AL_loadForm.php. You receive 0 as status code, which can mean many different things (see this). Basically, you need to check the logs of your server to know what happened. Did it receive the request? If so, was there an error? Also, you need to check the network tab of your browser console to see what response did you receive. That < is a big clue, it probably means that your server sends back some HTML, which might be too large, possibly due to a response dataset being too large or the server not handling posts well.

    EDIT:

    This PHP code is incorrect:

    <?php 
        if($_POST){ 
             if($_POST['json']){
                  echo json_encode($_POST['json']); //also tryed echo($_POST['json']);
                  } 
             }
    ?>
    

    I assume that you want to know whether the request is post and if so, then check whether it has a 'json' element, but $_POST is truey, even if it is a get request, since then it is an empty array and $_POST['json'] will lead to error if you do not have a 'json' element. Modify it like this:

    <?php 
        if($_SERVER['REQUEST_METHOD'] === 'POST'){ 
             if(isset($_POST['json'])){
                  echo json_encode($_POST['json']); //also tryed echo($_POST['json']);
                  } 
             }
    ?>
    

    Note, that you are encoding it into JSON and then wanting to alert it. You should not alert large json strings. Use console.log instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常