I read several information about that issue and tried the last 2 days to find that error, but unfortunately I wasn't able, so I hope you see it.
我阅读了有关该问题的几个信息,并在过去的两天内尝试找到该错误,但不幸的是我无法做到,所以我希望你能看到它。
The problem is the following: I have a search field where I enter any characters and get a autocompletion dropdown. It is working without issues when I'm not using any special characters. The dropdown is showing the Umlauts correctly, but when I enter "ü" or "ß" or something like that, the Dev Box of Google Chrome browser shows:
问题如下:我有一个搜索字段,我输入任何字符并获得自动完成下拉列表。当我没有使用任何特殊字符时,它可以正常工作。下拉列表正确显示了变形金刚,但当我输入“ü”或“ß”或类似内容时,Google Chrome浏览器的开发框显示:
"...search.php?term=%C3%BC 403 (Forbidden)"
“... search.php?term =%C3%BC 403(Forbidden)”
When I have a look in the "Network" section of Chrome after I entered an Umlaut I see:
Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:text/html; charset=iso-8859-1
在我输入变音符号后,当我查看Chrome的“网络”部分时,我看到:连接:保持活动内容编码:gzip内容类型:text / html;字符集= ISO-8859-1
But when I type a normal character I see:
Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
但是当我键入一个普通字符时,我看到:连接:保持活动内容编码:gzip内容类型:text / html;字符集= utf-8的
Without changing any source code. That is strange.
无需更改任何源代码。这很奇怪。
Here is the code I'm using:
这是我正在使用的代码:
HTML/JS:
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css">
<script type="text/javascript">
$(function() {
$("#cityzip").autocomplete({
source: "http://XXXXXXX/search.php" ,
select : function(event, ui) {
event.preventDefault();
var value = ui.item.value;
var sp_value = value.split(' / ');
var radius = sp_value[0];
var zip = sp_value[1];
$('#cityzip').val(ui.item.label);
$('#addradius').val(radius);
$('#zip').val(zip);
},
focus: function(event, ui) {
event.preventDefault();
}
});
});
the search.php
:
header("Content-Type:text/html; charset=utf-8");
/*
* database
*/
include 'data.php';
/*
* Results array
*/
$results = array();
/*
* Autocomplete formatter
*/
function autocomplete_format($results) {
foreach ($results as $result) {
echo $result[0] . '|' . $result[1] . "\n";
}
}
/*
* Search for term if it is given
*/
if (isset($_GET['term'])) {
$q = mb_strtolower(($_GET['term']),'UTF-8');
if ($q) {
foreach ($data as $key => $value) {
if (strpos(mb_strtolower(($key),'UTF-8'), $q) === 0) {
$results[] = array("label" => $key, "value" => $value);
if(++$i > 6) break;
}
}
}
}
/*
* Output format
*/
$output = 'autocomplete';
if (isset($_GET['output'])) {
$output = mb_strtolower($_GET['output'],'UTF-8');
}
/*
* Output results
*/
echo json_encode($results);
if (isset($_GET['c'])) {
echo $data[$_GET['c']];;
}
and the database data.php
:
和数据库data.php:
<?php
header("Content-Type:text/html; charset=utf-8");
$data = array(
"Berlin" => "29,4 / 10179",
"Berlin Adlershof" => "2,1 / 12489",
"Berlin Alt - Treptow" => "1,5 / 12435",
"Berlin Altglienicke" => "2,5 / 12524",
"Berlin Französisch - Buchholz" => "3,8 / 12205",
);
?>
I'm really grateful for any help. Thank you.
我真的很感激任何帮助。谢谢。
1 个解决方案
#1
0
You probably need to encode the search term before it is sent, otherwise it won't allow special characters to pass.
您可能需要在搜索词发送之前对其进行编码,否则将不允许特殊字符通过。
$encodedTerm = urlencode($_GET['term']);
#1
0
You probably need to encode the search term before it is sent, otherwise it won't allow special characters to pass.
您可能需要在搜索词发送之前对其进行编码,否则将不允许特殊字符通过。
$encodedTerm = urlencode($_GET['term']);