Ciao.
Ho questo script:
index.php
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
/** XHConn - Simple XMLHTTP Interface - [email]bfults@gmail.com[/email] - 2005-04-08 **
** Code licensed under Creative Commons Attribution-ShareAlike License **
** [url]http://creativecommons.org/licenses/by-sa/2.0/[/url] */
function XHConn(){
var xmlhttp, bComplete = false;
try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlhttp = new XMLHttpRequest(); }
catch (e) { xmlhttp = false; }}}
if (!xmlhttp) return null;
this.connect = function(sURL, sMethod, sVars, fnDone){
if (!xmlhttp) return false;
bComplete = false;
sMethod = sMethod.toUpperCase();
try {
if (sMethod == "GET"){
xmlhttp.open(sMethod, sURL+"?"+sVars, true);
sVars = "";
}
else{
xmlhttp.open(sMethod, sURL, true);
xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && !bComplete){
bComplete = true;
fnDone(xmlhttp);
}};
xmlhttp.send(sVars);
}
catch(z) { return false; }
return true;
};
return this;
}
function myTest(xhr){
alert(xhr.responseText);
}
var req= XHConn();
window.onload= function(){
var target = document.getElementById('my-buttom');
if(!target){return;}
target.onclick=function(){
var inputValue = document.getElementById('my-text').value;
var postVar= 'cat_title='+encodeURIComponent(inputValue);
alert(postVar);
req.connect('test.php','POST',postVar,myTest);
}
}
</script>
<body>
<form action="" method="post" name="frm">
<input id="my-text" name="my_test" type="text">
<input id="my-buttom" name="my_buttom" type="button" value="insert">
</form>
</body>
</html>
test.php
Codice PHP:
<?php
if(isset($_POST['cat_title'])){
echo $_POST['cat_title'];
}
else{
echo "Watch out";
}
?>
Bene provatelo se ne avete voglia
Lo script fa quello che ci si aspetta
Se apro Firebug nel reparto Net trovo le mie belle
variabili (Post cat_title mioinput Response mioinput) ma se invece dopo averlo aperto faccio partire
un'altra request trovo vuoto Post e nella Response Watch out ma nel mio debug vedo mioinput ho preso un colpo di sole o cosa