2011-06-10 3 views
0

이 AJAX 기능에 문제가 있습니다. 그러나 무엇이 보이지 않습니다. 방화범에 대한 응답이영구 오류 AJAX 기능

{"ioutput":"<div class=\"iavatar\"><\/div>\n<div class=\"ititle\">What a lovely course<br \/>\n<div class=\"iauthor\">pm master<\/div><\/div>\n<div class=\"icontent\">This intimate layout, with its undulating and springy fairways that zigzag in amongst the woodland setting, calls for accurate driving and precision shot-making into the well-bunkered greens; another classic Colt trademark. Position, not power, is the name of the game here.<\/div>"} 

된다 그러나이 기능을 오류에 가서 #dbody

의 콘텐츠를 넣어되지 않은 따르면

AJAX

$('.review').click(function() { 
    var idatas = $(this).attr('rel'); 
    var idata = 'idata=' + idatas; 

    $.ajax({ 
     type: 'POST', 
     url: '<?php echo $thisposturl;?>?review', 
     data: idata, 
     beforeSend: function() { 
      $(this).addClass('ractive'); 
     }, 
     dataType:'json', 
     success: function(data) { 
      $('#dbody').html(data.ioutput); 

      $('.cright').height($('#dropout').height()); 
      $('#dropout').addClass('dropopen'); 
     }, 
     error: function(data) { 
      $('#dbody').html('arse biscuity'); 
      $('.cright').height($('#dropout').height()); 
      $('#dropout').addClass('dropopen'); 
     } 
    }); 

PHP

<?php 

$rid = $_POST['idata']; 

$ireviews = get_posts('post_type=reviews&p='.$rid.'&numberposts=-1'); 

foreach ($ireviews as $ireview) : 
setup_postdata($post); 

$ioutput = '<div class="iavatar"></div> 
<div class="ititle">'.get_the_title($ireview).'<br /> 
<div class="iauthor">'.get_the_author($ireview).'</div></div> 
<div class="icontent">'.get_the_content($ireview).'</div>'; 

endforeach; 
echo json_encode(array('ioutput'=> $ioutput)); 


?> 

아이디어가 있으십니까? $.ajaxSetup()를 사용하여

+0

수신되는 응답 코드는 무엇입니까? –

+0

자바 스크립트 오류 란 무엇입니까? –

+0

잘 모르겠습니다. 하지만 위 오류 함수가 기본값이됩니다 –

답변

0

시도는 다음과 같이 올바른 오류를 얻을 :

$(function() { 
    $.ajaxSetup({ 
     error: function(jqXHR, exception) { 
      if (jqXHR.status === 0) { 
       alert('Not connect.\n Verify Network.'); 
      } else if (jqXHR.status == 404) { 
       alert('Requested page not found. [404]'); 
      } else if (jqXHR.status == 500) { 
       alert('Internal Server Error [500].'); 
      } else if (exception === 'parsererror') { 
       alert('Requested JSON parse failed.'); 
      } else if (exception === 'timeout') { 
       alert('Time out error.'); 
      } else if (exception === 'abort') { 
       alert('Ajax request aborted.'); 
      } else { 
       alert('Uncaught Error.\n' + jqXHR.responseText); 
      } 
     } 
    }); 
}); 

Ajax 호출에서 오류의 경우에, 당신은 적절한 경고를 받게됩니다.