====== JavaScript ======
* správně by se měl uvádět typ skriptu, ale v HTML5 se jako default bere ''text/javascript''
* identifikace objektu podle id
document.getElementById("texform")
$("#texform")
===== Asynchronní dotazy =====
* XMLHttpRequest
var http_req = new XMLHttpRequest();
var url = "myscript.php";
var params = "myparam=myparamvalue";
var displaybox = document.getElementById("display").innerHTML;
displaybox ="Loading data ...
";
http_req.onreadystatechange=function() {
if (http_req.readyState==4 && http_req.status==200) {
displaybox = http_req.responseText;
}
}
http_req.open("POST",url,true);
http_req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_req.send(params);
* dříve se používali ale spíš zápisy využívající jQUERY??? tj. ''$.ajax''
* jak odeslat formulář přes ajax?
* normálně do toho param je třeba narvat všechno z formuláře
* na to existují obecné funkce, co převedou všechny elementy na param string
* problém je ale s elementy typu select (multiselect), file, ...
* jak se posílá formulář s file přes ajax?
* buď přes iframe http://jecas.cz/ajax
* nebo přes FormData
* https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
* https://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax
var http_req = new XMLHttpRequest();
var url = "index.php";
var formdata = new FormData(document.getElementById("texform"));
document.getElementById("display").innerHTML="Loading data ...
";
http_req.onreadystatechange=function() {
if (http_req.readyState==4 && http_req.status==200) {
document.getElementById("display").innerHTML=http_req.responseText;
}
}
http_req.open("POST",url,true);
http_req.send(formdata);