Kód: Vybrať všetko
header('Content-type: text/html; charset=CP1250');Čaute,
mám nasledovný problém:
Potreboval som urobiť formulár, v ktorom ak niečo napíšem a stlačím MEDZERNÍK, tak mi to JavaScript odošle cez xmlHttp a v PHP súbore si to zoberiem cez $_GET. Potom s tým niečo spravím a vrátim to spať. Aby som to zjednodušil, tak v tomto prípade to proste len hneď vypíšem spať. PROBLÉM však nastal, keď som zistil, že namiesto toho aby sa mi vrátli presne tie isté písmenká, vráti sa mi niečo také: (priložený obrázok)
Čo sa týka JavaScriptu, tak som dosť lama, ešte som sa to len začal učiť, preto som aj väčšinu môjho JavaScriptu len našiel na internete a adaptoval na moje potreby
moje súbory vyzerajú nasledovne:
HTML:
Kód: Vybrať všetko
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8_slovak_ci" />
</head>
<title>AJAX suggest</title>
<script type="text/javascript" src="hladaj_script.js"></script>
<script type="text/javascript">
function submitonSpace(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if(charCode == "32") {
GetResult(document.getElementById("form").value);
}
}
</script>
<form>
<input id="form" type="text" size="30" onKeyDown="submitonSpace(event)" />
<div id="ViewResult"></div>
</form>
</body>
</html>Kód: Vybrať všetko
var xmlHttp
function GetResult(str)
{
if (str.length==0)
{
document.getElementById("ViewResult").innerHTML="";
document.getElementById("ViewResult").style.border="0px";
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="suggest.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("ViewResult").innerHTML=xmlHttp.responseText;
document.getElementById("ViewResult").style.border="1px solid #A5ACB2";
document.getElementById("ViewResult").style.padding="1px";
document.getElementById("ViewResult").style.width="500px";
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}Kód: Vybrať všetko
<?php
header('Content-type: text/html; charset=utf-8_slovak_ci');
$q=$_GET["q"];
echo $q;
?>