Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery ui自动完成+;ajax json数据_Jquery_Ajax_Json - Fatal编程技术网

使用jquery ui自动完成+;ajax json数据

使用jquery ui自动完成+;ajax json数据,jquery,ajax,json,Jquery,Ajax,Json,我想用 我已经采用了代码并尝试对其进行修改。使用原始代码,它可以工作(我可以得到城镇),当我适应我的数据时,它不会工作(没有列出任何内容,也没有显示任何内容)。我从php文件中获取json数据。这是我的密码: jquery: function log( message ) { $( "<div>" ).text( message ).prependTo( "#log" ); $( "#log" ).scrollTop( 0 ); } $( "

我想用

我已经采用了代码并尝试对其进行修改。使用原始代码,它可以工作(我可以得到城镇),当我适应我的数据时,它不会工作(没有列出任何内容,也没有显示任何内容)。我从php文件中获取json数据。这是我的密码:

jquery:

function log( message ) {
      $( "<div>" ).text( message ).prependTo( "#log" );
      $( "#log" ).scrollTop( 0 );
    }

    $( "#city" ).autocomplete({

      source: function( request, response ) {
            console.log(request.term);
        $.ajax({
            type: "POST",
          url: "/chercheabo",
          dataType: "jsonp",
          data: {
            achercher: request.term
          },
          success: function( data ) {
            response( $.map( data.myData, function( item ) {
              return {
                label: item.pseuDO + (item.pseuDO ? ", " + item.userID : "") + ", " + item.pseuDO,
                value: item.pseuDO
              }
            }));
          }
        });
      },
      minLength: 2,
      select: function( event, ui ) {
        log( ui.item ?
          "Selected: " + ui.item.label :
          "Nothing selected, input was " + this.value);
      },
      open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
      },
      close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
      }
    });
你能看到我的代码有什么错误吗?。。。 谢谢

更新:根据问题中的注释添加php文件

$options = array(); 
$result = mysqli_query($link,"select userid, pseudo from utili where pseudo like '%".strtolower($_POST[achercher])."%'"); 
while($uti = $result->fetch_object()) 
{ 
    $options['myData'][] = array( 'userID' => $uti->userid, 'pseuDO' => $uti->pseudo ); 
} 
echo json_encode($options);

[编辑]:将jsonp更改为json,它就可以工作了

你说的不工作到底是什么意思?请准确描述您面临的问题或错误。它只是不列出任何东西。。。控制台中没有任何事情发生,也没有错误…好的,使用开发人员工具,检查您的请求是否通过,如果通过,请发布您得到的响应。还添加了一个错误:函数(数据){console.log(数据)}成功后回调,看看你得到了什么。对不起,我不知道开发工具。。。我输入了错误:function(data){console.log(data)},在控制台中我有:
Object{readyState:4,getResponseHeader:function,getAllResponseHeaders:function,setRequestHeader:function,overrideMimeType:function…}
responseText:“{”myData:[{”userID:“11”,“pseuDO:“toto”},{”userID:“20”,“pseuDO:“blogo”}”
{"myData":[{"userID":"11","pseuDO":"toto"},{"userID":"20","pseuDO":"blogo"}]}
$options = array(); 
$result = mysqli_query($link,"select userid, pseudo from utili where pseudo like '%".strtolower($_POST[achercher])."%'"); 
while($uti = $result->fetch_object()) 
{ 
    $options['myData'][] = array( 'userID' => $uti->userid, 'pseuDO' => $uti->pseudo ); 
} 
echo json_encode($options);