Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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页面_Jquery_Mysql_Ajax - Fatal编程技术网

分离自动完成jquery页面

分离自动完成jquery页面,jquery,mysql,ajax,Jquery,Mysql,Ajax,我已经从jquery中创建了自动完成函数。我已经测试过了,除了打开页面时加载太长外,它工作正常。因此,我想再次制作一个文件,以便可以更快地打开或重新加载此页面 这是自动完成文件 <?php include "../config/config.php"; $region = $_GET['region']; ?> <script> $(function() { var availableTags = [ <?php $sql=mysql_query("SE

我已经从jquery中创建了自动完成函数。我已经测试过了,除了打开页面时加载太长外,它工作正常。因此,我想再次制作一个文件,以便可以更快地打开或重新加载此页面

这是自动完成文件

<?php
include "../config/config.php";
$region = $_GET['region'];
?>
<script>
$(function() {
var availableTags = [
 <?php
     $sql=mysql_query("SELECT country_name FROM country WHERE region='$region' ORDER BY country_name");

     while($f=mysql_fetch_array($sql))
     {
        echo " '".$f['country_name']."', ";
     }
 ?>

];
function split( val ) {
  return val.split( /,\s*/ );
}
function extractLast( term ) {
  return split( term ).pop();
}

$( "#tags" )
  // don't navigate away from the field on tab when selecting an item
  .bind( "keydown", function( event ) {
    if ( event.keyCode === $.ui.keyCode.TAB &&
        $( this ).autocomplete( "instance" ).menu.active ) {
      event.preventDefault();
    }
  })
  .autocomplete({
    minLength: 0,
    source: function( request, response ) {
      // delegate back to autocomplete, but extract the last term
      response( $.ui.autocomplete.filter(
        availableTags, extractLast( request.term ) ) );
    },
    focus: function() {
      // prevent value inserted on focus
      return false;
    },
    select: function( event, ui ) {
      var terms = split( this.value );
      // remove the current input
      terms.pop();
      // add the selected item
      terms.push( ui.item.value );
      // add placeholder to get the comma-and-space at the end
      terms.push( "" );
      this.value = terms.join( ", " );
      return false;
    }
  });
  });
</script>
</head>
<body>

<div class="ui-widget">
<label >Type country: </label>
<input id="tags" size="50">
</div>

$(函数(){
var availableTags=[

将PHP放在一个单独的文件中,例如名为“getRegions.PHP”


我不明白,你想做什么?你想从外部文件中追加脚本,在页面完全加载后运行脚本,还是什么?@Sojtin是的,我想创建与jquery分离的php文件,所以我认为重新加载页面会更快
<?php
     include "../config/config.php";
     $region = $_GET['term']; //this has to be changed to "term" !!!!

     $sql=mysql_query("SELECT country_name FROM country WHERE region='$region' ORDER BY country_name");

     $regions = array();    
     while($f=mysql_fetch_array($sql))
     {
        $regions[] = $f['country_name'];
     }

     echo json_encode($regions);