drvxnivoqf17568697 2011-06-10 16:47
浏览 28

AJAX函数永久性错误

Something is wrong with this AJAX function but I do not see what.

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));


?>

According to Firebug the response is this

{"ioutput":"<div class=\"iavatar\"><\/div>
<div class=\"ititle\">What a lovely course<br \/>
<div class=\"iauthor\">pm master<\/div><\/div>
<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>"}

But it is going to error function and not putting the content in #dbody

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanbarong4321 2013-01-28 13:33
    关注

    Try using the $.ajaxSetup() to get the correct error like this:

    $(function() {
        $.ajaxSetup({
            error: function(jqXHR, exception) {
                if (jqXHR.status === 0) {
                    alert('Not connect.
     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.
    ' + jqXHR.responseText);
                }
            }
        });
    });
    

    In case of any error in the Ajax call, you will get proper alert.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。