dslkchyv673627 2014-05-30 22:53
浏览 35

我的自动填充结果显示为html标记

When I start writing on my input, my results appear with html tags, for example, if I search for "t" I get: Title<p><span>Content</span></p>. And I want Title Content, without no html tags.

This is my php:

$search = isset($_GET['term']) ? $_GET['term'] : "";
$pdo = conecting();
$read = $pdo->prepare("SELECT * from articles WHERE title LIKE ?");   
$read ->bindValue(1, "%$search%", PDO::PARAM_STR);
$read ->execute();

$data = array();

while($res = $read ->fetch(PDO::FETCH_ASSOC))
  {
     $data[] = $res['title'].'-'.$res['content'];
  }
echo json_encode($data); 

This is my jQuery to start autocomplete:

$('.j_autocomplete').autocomplete({

        source: 'http://localhost/project/tpl/search.php'
        select: function(event, ui){
            var get= ui.item.value; 
            returndata(get);
        },
        change: function(data)
        {
            returndata($(this).val());
        }
    });

Do you know how to solve this?

  • 写回答

1条回答 默认 最新

  • dongti8535 2014-05-30 23:03
    关注

    Try using this way:

    Add this code after autocomplete initialization:

    .data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append("<a>" + item + "</a>")
             .appendTo(ul);
     };
    

    Like this:

    $('.j_autocomplete').autocomplete({
    
        source: 'http://localhost/project/tpl/search.php'
        select: function(event, ui){
            var get= ui.item.value; 
            returndata(get);
        },
        change: function(data)
        {
            returndata($(this).val());
        }
    }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append("<a>" + item + "</a>")
             .appendTo(ul);
     };
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大