getJson没有工作没有控制台错误但在chrome开发人员工具中没有响应

时间:2016-11-04 17:20:33

标签: javascript php jquery getjson

function loadNewsList(pageindex){
    var searchString = document.getElementById("searchBox");
    $('#ulnews').append("<li>into the function</li>");

    var sendData = {
        pageIndex: pageindex,
        searchstring: searchString.value
    };

    $.getJSON("handleListDisplay.php", sendData, function(jsonData) {
        $('#ulnews').append("<li>gets in to getjson</li>");         
        $.each(jsonData.news, function(index, newsdata){
            var time = timeConverter(newsdata["time"]);
            var data = newsdata["content"];
            var content = data.substr(0,50);    
            $('#ulnews').append("<li>get to .each function</li>");
            $('#ulnews').append("<li><a href='displayNewsEntry.php?newsId=" + newsdata["id"] + "' class='newsHeadline'>" + newsdata["headline"] + "</a><h5>" + time + "</h5><h4>" + content + "...</h4></li>");
        });

        $('#ulnews').append("<li>outside of .each function</li>");      
    });
    $('#ulnews').append("<li>outside of getJSON</li>"); 
}

append用于我的调试用途,浏览器只显示在函数和getJSON之外 我的php文件看起来像这样

<?php
    $conn = mysqli_connect('server', 'myusername', 'mypassword') or die ('Failed to Connect '.mysqli_error($conn));
    mysqli_select_db($conn,'dbname') or die ('Failed to Access DB'.mysqli_error($conn));

    $searchString = $_GET["searchstring"];

    if ($searchString.length == 0) 
    {
        $query = "select count(*) from news";
    }
    else 
    {
        $query = "select count(*) from news where headline like '%".$searchString."%'";
    }

    $json = array();

    $result = mysqli_query($conn, $query) or die ('Failed to query '.mysqli_error($conn));
    $row = mysqli_fetch_row($result);   
    $row_count = $row[0];
    $json[] = array('NoOfRecords' => $row_count);

    $pagenum = 5 * ($_GET["pageIndex"]);

    if ($searchString.length == 0)
    {
        $query = "select * from news order by time desc, headline asc limit 5 offset ".$pagenum;
    }
    else
    {
        $query = "select * from news where headline like '%".$searchString."%' order by time desc, headline asc limit 5 offset ".$pagenum;
    }

    $result = mysqli_query($conn, $query) or die ('Failed to query '.mysqli_error($conn));

    while ($row2 = mysqli_fetch_array($result)) 
    {
        $json[] = array('id'=>$row2['newsID'], 'headline'=>$row2['headline'], 'content' => $row2['content'], 'time' =>$row2['time']);
    }

    print json_encode(array('news'=>$json));    
?>

我的网页很好,刚刚进入函数和ul id = ulnews中的.each函数之外,但是点击handleListDisplay.php时开发工具网络选项卡左边有一个窗口有标题预览响应和时间,在那个响应中它是空白的

我的问题是我似乎无法找到任何错误,但

$('#ulnews').append("<li><a href='displayNewsEntry.php?newsId=" + newsdata["id"] + "' class='newsHeadline'>" + newsdata["headline"] + "</a><h5>" + time + "</h5><h4>" + content + "...</h4></li>");

不会在<ul id="ulnews">...</ul>

中输出任何内容

我似乎无法找到它可能显而易见的问题,请原谅我作为菜鸟

0 个答案:

没有答案