Ajax结果显示未定义

I want to ues ajax polling for show user update by followers like facebook.

So I collect this code and apply in my page, Which append only 'undefined' one after one.

What is my wrong here in my code please.

At below I give my full polling script and related file

my Table name: updateside

id - work_id - parent_id - from_id - to_id - sub - detail - img - created
..........................................................................

AI - work_id, parent_id etc. all data submit by user post form

My JavaScript

function waitForMsg(){

    $.ajax({
        type: "GET",
        url: "upsidenew.php",
        async: true, 
        cache: false, 
        timeout:50000, 
        success: function(data){ 
            if(data) {
               $("#updatetime").append('<div class="upbox1">' + data.detail + '</div>');
            }
            setTimeout(
                waitForMsg, 
                1000 
            );
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            addmsg("error", textStatus + " (" + errorThrown + ")");
            setTimeout(
                waitForMsg, 
                15000);
        }
    });
}

$(document).ready(function () {
    waitForMsg(); 
});

upsidenew.php

$parent = //collect from other query
date_default_timezone_set('Asia/Dhaka');
$timestamp = date("M j, y; g:i a", time() - 2592000);

$u = mysqli_query($dbh,"SELECT * FROM updateside WHERE `parent_id`='".$parent."' AND `created` > '".$timestamp."' ORDER BY created DESC") or die(mysqli_error($dbh));
$response = array();
while ($row = mysqli_fetch_array($u)) {
    $response['from_id'] = $row['from_id'];
    $response['parent_id'] = $row['parent_id'];
    $response['to_id'] = $row['to_id'];
    $response['sub'] = $row['sub'];
    $response['detail'] = $row['detail'];
    $response['img'] = $row['img'];
    $response['time'] = $row['created'];

    ?><script><?php echo '(Content-Type: application/json)';?></script><?php
    echo json_encode($response);
    exit;
}

Add your ajax request dataType as "dataType: 'json'"

$.ajax({
        type: "GET",
        url: "upsidenew.php",
        async: true, 
        cache: false, 
        timeout:50000, 
        dataType: 'json'
        success: function(data){ 
        if(data) {
           $("#updatetime").append('<div class="upbox1">' + data.detail + '</div>');
        }
            setTimeout(
                waitForMsg, 
                1000 
            );
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            addmsg("error", textStatus + " (" + errorThrown + ")");
            setTimeout(
                waitForMsg, 
                15000);
        }
    });

if you don't set the datatype of your ajax call explicity to json you need to parse the result with:

jsondata = $.parseJSON(data);
alert(jsondata.detail);

as shown in

http://api.jquery.com/jquery.ajax/

If you're returning JSON, you shouldn't output anything other than echo json_encode($response). This line:

?><script><?php echo '(Content-Type: application/json)';?></script><?php

should be:

header('Content-type: application/json');