簡體   English   中英

無法在jquery窗口中顯示評論

[英]cannot display reviews in jquery window

我只想在對話框上顯示評論,但不起作用。 請幫我。 我試圖做一個星期。

以下是應顯示的數據:

{"results":[{"review_text":"good"},{"review_text":"not bad"},{"review_text":"great"}]}

這是我的查看代碼:

<div id="see_all_reviews">  
  <div id="load_reviews"></div>
  </div>  
<?php
$data = array(
    'name' => $places_id,
    'class' => 'all_reviews',    
    'content' => 'Reviews'    
    );
   echo form_button($data);
?>

這是我的js文件:

$(".all_reviews").click(function() {
    var self = this;
    var places_id_all_reviews = $(self).attr("name");
    $.post('filter/get_reviews', { id: id }, function(data) {
        var reviews_text = data.results[0].review_text;
        $("#load_reviews").text(reviews_text);
    });
}, "json").error(function() {
    $("#load_reviews").text(data.message);
});

$("#see_all_reviews").dialog({
    autoOpen: false,
    title: "Reviews",
    modal: true,
    draggable: false,
    width: 600,
    height: 600,
    close: function() {
        $(this).dialog('destroy');
    }
});
});

試試這個更新

var places_id_all_reviews = $(self).attr("name");
    $.post('filter/get_reviews', {
        id: id
    }, function(data) {

        $.each(data.results, function(i, res) {

            // Let's create the DOM
            var item = $('<div>'),
                title = $('<h1>'),
                info = $('<p>');


            info.text(res.review_text);

            // Append the infos to the item
            item.append(title, info);

            // Append the item to the container
            item.appendTo($("#load_reviews"));
        });

        $("#see_all_reviews").dialog({
            autoOpen: false,
            title: "Reviews",
            modal: true,
            draggable: false,
            width: 600,
            height: 600,
            close: function() {
                $(this).dialog('destroy');
            }
        });
    });
    });
    }, "json").error(function() {
        $("#load_reviews").text(data.message);
    });

更新

嘗試清空評論包含的html,這部分代碼如下

close: function() {
                     $("#load_reviews").html("");
                    $(this).dialog('destroy');
                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM