我收到一个带有特殊字符(á')的ajax的错误,当我选择南美时我有两个选择器,秘鲁没有返回任何东西,但告诉我这个fiebug
获取http://www.example.com/deconsultas/index.php?controller=galerias&action=view&pais=Per%FA
我有这个javascript;
$("#listar").click(function(){
var pais = $("#pais2").val();
$.get("index.php?controller=galerias&action=view&pais="+pais, function(data){
$("#resultados").html(data);
});
return false;
});
public function view()
{
$db = new Galerias_Model;
if (BM_Validations::isAjax()) :
$this->setTemplate("galerias");
$this->setFilenames("galerias", 'view.html');
$pais = htmlentities($_GET['pais']);
$pais=trim($pais);
$galerias = $db->getImages($pais);
if ($galerias) :
$this->assignVar('ENCONTRO', true);
$ciudad = "";
foreach ($galerias as $row) :
$mostrarCiudad = false;
if ($ciudad!=$row['ciudad']) :
$mostrarCiudad = true;
$cont = 0;
endif;
$cont++;
$this->assignBlock('galerias', array(
'ID' => $row['id'],
'MOSTRAR_CIUDAD' => $mostrarCiudad,
'CIUDAD' => $row['ciudad'],
'IMAGEN' => $row['imagen'],
'SALTO_LINEA' => (($cont % 5) == 0)
));
$ciudad = $row['ciudad'];
endforeach;
endif;
$this->tpl->display('galerias');
endif;
die();
}
这是接收该网址的php,它看起来像.htaccess?
我有这个:
#Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /deconsultas/index.php [L]
RewriteRule ^([^/]*)/$ /deconsultas/index.php?controller=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /deconsultas/index.php?controller=$1&id=$2&titulo=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /deconsultas/index.php?controller=$1&action=$2 [L]
RewriteRule ^([^/]*)\.dc$ /deconsultas/index.php?controller=operador&url=$1 [L]
RewriteRule ^panel/([^/]*)$ /deconsultas/index.php?controller=panel&action=$1 [L]
#RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /deconsultas/index.php?controller=$1&action=$2&id=$3 [L]
RewriteRule ^admin/([^/]*)$ /deconsultas/index.php?controller=admin&action=$1&inactivos [L]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
答案 0 :(得分:0)
构建查询字符串时,您必须对每个组件进行url编码,例如á
编码为%C3%A1
$("#listar").click(function(){
var pais = $("#pais2").val();
var urlEncodedPais = encodeURIComponent(pais);
$.get("index.php?controller=galerias&action=view&pais=" + urlEncodedPais , function(data){
$("#resultados").html(data);
});
return false;
});
更好的方法是让jQuery为你做https://api.jquery.com/jQuery.param/
$("#listar").click(function(){
var pais = $("#pais2").val();
var params = {
controller: 'galerias',
action: 'view',
pais: pais
};
$.get("index.php?"+ $.param(params), function(data){
$("#resultados").html(data);
});
return false;
});
请注意,这也适用于键值名称,因此如果您愿意,可以将参数调用país
(但我不推荐)
jQuery.param({"país": 'Índia'})
> "pa%C3%ADs=%C3%8Dndia"