简体   繁体   English

如何使用jQuery在ListView中的多个列表项中显示数据

[英]How to display the data in multiple list items in listview using jquery

I'm getting the database data using php file. 我正在使用php文件获取数据库数据。 When i'm loading that php file using jquery that data will display in the same list item in listview. 当我使用jquery加载该php文件时,该数据将显示在listview的同一列表项中。 I have multiple titles but its displaying in the single list item. 我有多个标题,但显示在单个列表项中。 When i'm using $.each its showing error in jquery-1.9.1.min.js file where i did wrong. 当我使用$.each在我做错的jquery-1.9.1.min.js文件中显示错误。 Error as : TypeError:invalid 'in' operand e . 错误为:TypeError:无效的'in'操作数e。

js code: js代码:

$.ajax({
    type: "GET",
    url: "index.php",
    datatype: "jsonp",
    success: function(json) {
        $.each(json, function(i, data) {
    $("#section_list").append('<li><a href="#" id="'+ i +'"><h2>' + data.Subject + ' </h2></a></li>');
        });
    $("#section_list").listview('refresh');
}
});

php code : PHP代码:

<?php
    class db extends SQLite3
    {
        function __construct() {

            $this -> open('database.db');
        }
    }

    $db = new db();
    if (!$db) {
        echo $db-> lastErrorMsg();

    }
    else
    {
    }

    $sql =<<<EOF
      SELECT distinct(Subject,Category) from Data;
EOF;

$ret = $db->query($sql);

while($row = $ret->fetchArray(SQLITE3_ASSOC) ){
      echo $row['Subject'] ."<br />";

   }

  $db->close();
?>

Thanks in Advance. 提前致谢。

i guess each won't work with a json object...try this: 我想每个人都无法使用json对象...请尝试以下操作:

$.each($.parseJSON(json), function(i, data) {
    //your code here
}

...tough i don't think your php is giving out json...if it's just a string try ...坚韧,我不认为您的php发出json ...如果只是字符串,请尝试

var split = json.split("<br />");

$.each(split, function(i, data) {
    //your code here
}

...if you're not sure about that, do console.log(json) ...如果不确定,请执行console.log(json)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM