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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵