首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在本地主机上自动完成工作,但在服务器上不完成

在本地主机上自动完成工作,但在服务器上不完成
EN

Stack Overflow用户
提问于 2016-04-01 11:36:39
回答 1查看 1.2K关注 0票数 1

我有一个带有自动完成函数的搜索公式,它在本地主机上工作得很好,但是一旦我把它放到远程服务器上,它就停止工作了。

我希望你能帮助我。以下是一些守则:

index.php:

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="de">
 <head>
    <?
    header("Content-Type: text/html; charset=iso-8859-1"); 
    
    ?>

    <link rel="stylesheet" href="css/jquery-ui-1.10.3.custom.min.css" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    
    <link rel="stylesheet" href="css/style.css" />
    

    <script src="js/jquery-1.10.2.min.js"></script> 
    <script src="js/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="js/bootstrap.min.js"></script> 
</head>
<body>  

    <div id="wrap">
        <h1 class="text-center">Suche</h1>
        <div class="row">
            <div class="col-xs-6 col-sm-4 col-md-4 col-xs-offset-6 col-sm-offset-4 col-md-offset-4">
                <form method='POST' action=''>
                <input type='text' name='food' id="country_name" class="form-control txt-auto"/>
                <input type='submit' value='search'>
                </form>

            </div>

        </div>
        
    </div>
    

    
    <script src="js/auto.js"></script>
</body>
</html>

ajax.php

代码语言:javascript
复制
<?php


header('Content-Type: text/html; charset=UTF-8');

require_once 'config.php';

if($_GET['type'] == 'country'){
    $result = mysql_query("SELECT *
        FROM table
        WHERE name LIKE '%".strtoupper($_GET['name_startsWith'])."%'
        LIMIT 8");  
    $data = array();
    while ($row = mysql_fetch_array($result)) {
        array_push($data, $row['name']);    
    }   
    echo json_encode($data);
}

?>

auto.js

代码语言:javascript
复制
   $('#country_name').autocomplete({
                    source: function( request, response ) {
                        $.ajax({
                            url : 'ajax.php',
                            dataType: "json",
                            data: {
                               name_startsWith: request.term,
                               type: 'country'
                            },
                             success: function( data ) {
                                 response( $.map( data, function( item ) {
                                    return {
                                        label: item,
                                        value: item
                                    }
                                }));
                            }
                        });
                    },
                    autoFocus: true,
                    minLength: 0        
                  });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-01 11:42:23

您在HTML中缺少了php,如果您的服务器没有设置为简短的打开标记--可能会导致问题,如注释中所示--在头声明之前不应该有任何html内容。

应:

代码语言:javascript
复制
   <?php
    header("Content-Type: text/html; charset=iso-8859-1"); 
    ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36355356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档