【问题标题】:Information is not appended and displayed in jquery Collapsiblejquery Collapsible 中不附加和显示信息
【发布时间】:2014-11-08 19:50:51
【问题描述】:

我正在再次研究这个主题,但我还没有找到任何解决方案

一个。我所做的操作:我使用 PDO 构建查询以使用 PHP 从 DB 获取信息,然后将结果添加到关联数组中并对其进行编码,以便使用 ajax 发送它们。最后,我使用 $.ajax 来获取信息并构建 jquery collapsible

b.问题:信息未附加到可折叠结构的内部。 ajax接收到的数据的console.log没有显示任何信息

数据库应用

表格:错误 ID、类型、状态、严重性、系统、浏览器、标题、描述、创建日期

表:项目 id、projectname、status、description、start_date、due_date

应用的结构是:

  • inc/errorList.php
  • inc/connection.php
  • index.html(多页文件)

文件:errorList.php

<?php
    // Import the connection to the database  
    require_once 'connection.php';

    // Get the instance
    $conn = dbConnect();

    // Build the query 
    $sql = " SELECT bg.bug_id, py.project, bg.type, bg.status, bg.severity, bg.system, bg.browser, bg.title, bg.description,bg.creation_date FROM bugs bg, projects py WHERE bg.projectid = py.id ";

    // Run the query and gets the results
    $result = $conn->query($sql)->fetchAll(PDO::FETCH_ASSOC);

    // Build an iteration and create an associative array   
    foreach ($result as $row){

    $return[]=array(
                'bug_id'=>$row['bug_id'],
                'project'=>$row['project'],
                'type'=>$row['type'],
                'status'=>$row['status'],
                'severity'=>$row['severity'],
                'system'=>$row['system'],
                'browser'=>$row['browser'],
                'title'=>$row['title'],
                'description' => $row['description'],
                'creation_date'=>$row['creation_date']);
     }

     // Encode the array 
     echo json_encode($return);

?>

文件:index.html/页面:#bugs

在 html 文件中我添加了 div "SET"

<div data-role="collapsible-set" id="set"><div>
    <script type="text/javascript">

        $(document).on('pagebeforeshow', '#bugs', function (){

                $.ajax({
                    url: 'inc/errorList.php',
                    data: "",
                    dataType: 'json',
                    success: function(data)
                    {
                        // Create the variable content to concatenate the results
                        var content = "";

                        // Build an iteration of the information received in data

                        for (var i = 0; i < data.length; i++) {

                            // Add the header of the collapsible  
                            content = "<div data-role='collapsible' data-collapsed-icon='arrow-r'   data-expanded-icon='arrow-d' data-iconpos='right' data-theme='a'><h3> " + data[i].bug_id + ' - ' + data[i].title + "</h3>" + "<ul data-role='listview' data-inset='true'  data-theme='a'>";

                            // Concatenate the header with the information retreived
                             content = content +
                            '<li>Project: ' + data[i].project + '</li>' +
                            '<li>Type: ' + data[i].type + '</li>' +
                            '<li>Status: ' + data[i].status + '</li>' +
                            '<li>Severity: ' + data[i].severity + '</li>' +
                            '<li>Browser: ' + data[i].browser + '</li>' +
                            '<li>Creation Date ' + data[i].creation_date + '</li>' +
                            '<li>Detail: ' + data[i].description + '</li>' ;

                            content = content + '</ul>';
                            content = content + "</div>";

                            // Append the content into the div     
                            $("#set").append(content);
                        }

                        // Refresh the Collapsible 
                        $("#set").collapsibleset("refresh").enhanceWithin();
                       }
                    });
            });
    </script>  

【问题讨论】:

  • 你在说什么“detail”?
  • 字段“详细信息”是错误架构中的一列
  • 因为你在 ; 后面少了一个分号。在content 第一个。此外,您必须以var content = ""; 的方式声明变量内容,否则您将在字符串的开头得到undefined
  • jsfiddle.net/Palestinian/tfvy8mwo 也可以使用.collapsibleset("refresh") 重新增强collapsibleset。
  • 我什么都没应用,问题是当一个字段被添加到 php 文件和 jquery 的结构中时

标签: php ajax json jquery-mobile jquery-mobile-collapsible


【解决方案1】:

是的,我终于找到了错误!问题是“描述”字段中某些单词的重音符号,下面我添加最终代码:

文件:errorList.php

<?php
// Import the connection to the database  
require_once 'connection.php';

// Get the instance
$conn = dbConnect();

// Build the query 
$sql = " SELECT bg.bug_id, py.project, bg.type, bg.status, bg.severity, bg.system, bg.browser, bg.title, bg.description,bg.creation_date FROM bugs bg, projects py WHERE bg.projectid = py.id ";

// Run the query and gets the results
$result = $conn->query($sql)->fetchAll(PDO::FETCH_ASSOC);

// Build an iteration and create an associative array   
foreach ($result as $row){

$return[]=array(
            'bug_id'=>$row['bug_id'],
            'project'=>$row['project'],
            'type'=>$row['type'],
            'status'=>$row['status'],
            'severity'=>$row['severity'],
            'system'=>$row['system'],
            'browser'=>$row['browser'],
            'title'=>$row['title'],
            'description' => $row['description'],
            'creation_date'=>$row['creation_date']);
 }

header("Content-type: application/json", true);
echo json_encode($return);
exit;

?>

文件:json.js

address = 'inc/errorList.php';


$.ajax({url: address,
        cache: false,
        data: "",
        dataType: 'json',
        success: function(new_data){

  // Create the variable content to concatenate the results
                    var content = "";

                    // Build an iteration of the information received in data

                    for (var i = 0; i < data.length; i++) {

                        // Add the header of the collapsible  
                        content = "<div data-role='collapsible' data-collapsed-icon='arrow-r'   data-expanded-icon='arrow-d' data-iconpos='right' data-theme='a'><h3> " + data[i].bug_id + ' - ' + data[i].title + "</h3>" + "<ul data-role='listview' data-inset='true'  data-theme='a'>";

                        // Concatenate the header with the information retreived
                         content = content +
                        '<li>Project: ' + data[i].project + '</li>' +
                        '<li>Type: ' + data[i].type + '</li>' +
                        '<li>Status: ' + data[i].status + '</li>' +
                        '<li>Severity: ' + data[i].severity + '</li>' +
                        '<li>Browser: ' + data[i].browser + '</li>' +
                        '<li>Creation Date ' + data[i].creation_date + '</li>' +
                        '<li>Detail: ' + data[i].description + '</li>' ;

                        content = content + '</ul>';
                        content = content + "</div>";

                        // Append the content into the div     
                        $("#set").append(content);
                    }

                    // Refresh the Collapsible 
                    $("#set").collapsibleset("refresh").enhanceWithin();
                   },
        error: function (request,error) {

            //var err = eval("(" + xhr.responseText + ")");
            //alert(err.Message);
            // This callback function will trigger on unsuccessful action                
            alert('Connection Error!');
            alert('Error: ' + error);
            //console.log(new_data);

        }

    });           

 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多