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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分