jQuery自动完成功能不显示列表,即使数据以json格式正确返回

时间:2019-01-23 04:55:21

标签: jquery jquery-ui-autocomplete

我的jquery自动完成功能在此之前就已经正确运行了,但是突然它不起作用并且没有显示从我的数据库返回的数据。我不知道是什么真正导致了问题。也许任何人都可以帮忙。

$('#search').autocomplete({
source:'vot/handle_vot.php?p=find_vot', 
    minLength:3,
    dataType: "json",
    select: function( event, ui ) {        
        event.preventDefault();
        if (ui.item.value!=null) {                                  
            $( "#search" ).val( ui.item.label );
            $( "#vote_display" ).val( ui.item.value );
        } 
      },
    // optional
    html: true, 
    // optional (if other layers overlap the autocomplete list)
    open: function(event, ui) {
            $(".ui-autocomplete").css("z-index", 1061);
    }
   // appendTo : modalAddPub                
}, "json");

当我运行脚本时,在chrome开发者工具的网络部分下,返回的结果如下...

 <meta http-equiv=refresh content='2; url=../index.php?page=allocation&vot=&tahun='>{
"0":{"value":"59300","label":"59300-Siti Salina Abdullah Dr. "},"1":{"value":"59301","label":"59301-Khatijah Omar Dr."},
"2":{"value":"59302","label":"59302-Hafiza Aishah Hashim (Dr. )"},
"3":{"value":"59303","label":"59303-Roshaiza Taha Dr. "},
"4":{"value":"59304","label":"59304-Nor Raihan Mohamad Dr. "},
"5":{"value":"59305","label":"59305-Ibrahim Mamat Prof. Dr. "},
"6":{"value":"59306","label":"59306-Tengku Sifzizul Tengku Muhammad Prof. Dr. "},
"7":{"value":"59307","label":"59307-Abol Munafi Ambok Bolong (Prof. Madya Dr.) "},
"8":{"value":"59308","label":"59308-Chuah Tse Seng (Prof. Madya Dr. )"},
"9":{"value":"59309","label":"59309-Mariam Taib (Prof. Madya Dr. )"},
"10":{"value":"59310","label":"59310-Hazlina Ahamad Zakeri  (Dr.)"}}

enter image description here

1 个答案:

答案 0 :(得分:0)

您不是从服务器返回JSON;而是从服务器返回JSON。您将返回带有JSON的元标记,如字符串作为文本内容。

您需要在客户端上提取字符串或删除meta标签,然后再发送内容。