dongmu1989 2016-04-01 11:36 采纳率: 0%
浏览 50
已采纳

自动完成在localhost上工作,但不在服务器上工作

as explained in the title, I have a search formular with an autocomplete function wich works just fine on localhost, but as soon as I put it on a remote server it stops working.

I hope you can help me. Here is some Code:

index.php:

<!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

<?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

   $('#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        
                  });
  • 写回答

1条回答 默认 最新

  • doupuzhimuhan9216 2016-04-01 11:42
    关注

    You are missing the php in the HTML and if your server isn't set up for short open tags- may cause an issue, and as shown in the comments - there should not be any html content before the header declaration.

    should be:

       <?php
        header("Content-Type: text/html; charset=iso-8859-1"); 
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭