为了账号安全,请及时绑定邮箱和手机立即绑定

js错误Uncaught RangeError: Maximum call stack size exceeded

js错误Uncaught RangeError: Maximum call stack size exceeded

MYYA 2019-04-19 16:29:48
首先调用get_content()方法,然后在get_content方法中调用handle_content()方法,然后在handle_content方法中调用post_content()方法,最后在post_content方法中再调用get_content()方法,不知到该怎样避免超出内存呢?functionget_content(){$.ajax({url:'/air_ajax.php',type:'get',dataType:'json',timeout:1000,async:false,success:function(json){if(json.status){handle_content(json.article);}else{console.log('getarticlenone');}}});}functionhandle_content(article){if(!article){console.log('articleisillegal');console.log(article);return;}var$box=$(''+article.content+'');var$children=$box.find('#content').children();if($children.length>0){$children.each(function(){//console.log('hello');vartag=this.nodeName.toLowerCase();if(this.nodeType==1&&tag!=='div'&&tag!=='p'){varhtml=$(this).html();//console.log(this);$(this).replaceWith(''+html+'');}});}$box.find('img').each(function(){$(this).attr('src','/img/load_common.gif');});if($box.find('#content').length>0){varhtml=$box.find('#content').html();}else{varhtml=$box.html();}//var$html=$(''+html+'');ue.setContent(html);ue.execCommand('selectall');ue.execCommand('removeformat');varcontent=ue.getContent();var$html=$(''+content+'');$html.find('img').each(function(){varsrc=$(this).attr('src');vardatasrc=$(this).attr('data-src');$(this).removeAttributes();$(this).attr('src',src).attr('data-src',datasrc);});$html.find('a').remove();varhtml=$html.html();data={id:article.id,content:html};post_content(data);}**varcount;**functionpost_content(data){**count++;**$.ajax({url:'/air_ajax.php',type:'post',dataType:'json',timeout:1000,async:false,data:data,success:function(json){if(json.status){console.log('processsuccess'+id);**if(count>400){setTimeout(get_content,5000);count=0;}else{get_content();}**}else{console.log(json.errorInfo);status=false;}}});}
查看完整描述

2 回答

?
翻阅古今

TA贡献1780条经验 获得超5个赞

这是无限递归呐。。没有终止条件肯定会爆栈啊
建议把get_content()改成setTimeout(get_content,0),使之成为异步调用,自然就瓦解了递归栈
                            
查看完整回答
反对 回复 2019-04-19
  • 2 回答
  • 0 关注
  • 826 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信