par
Sékiltoyai » 21 mai 2007, 17:39
<html>
<head>
<script language="Javascript" type="text/javascript">
var xhr_object = null;
if(window.XMLHttpRequest)
{
xhr_object = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
}
function maj()
{
xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 1)
{
xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr_object.send(
"arg1="+document.getElementById("arg1").value+
"&&arg2="+document.getElementById("arg2").value
);
}
else if(xhr_object.readyState == 4)
{
document.getElementById("result").value = xhr_object.responseText;
}
xhr_object.open("POST","add.php",true);
}
}
</script>
</head>
<body>
<input type="text" size="3" id="arg1" value="0" onChange="maj()" />
<input type="text" size="3" id="arg2" value="0" onChange="maj()" />
<input type="text" size="5" id="arg3" value="0" />
</body>
</html>
Et dans add.php :
<?php
$arg1 = isset($_POST['arg1'])?intval($_POST['arg1']):0;
$arg2 = isset($_POST['arg2'])?intval($_POST['arg2']):0;
echo ($arg1+$arg2);
?>
C'est un exemple, je n'ai pas testé, mais moralement c'est bon...
[php]<html>
<head>
<script language="Javascript" type="text/javascript">
var xhr_object = null;
if(window.XMLHttpRequest)
{
xhr_object = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
}
function maj()
{
xhr_object.onreadystatechange = function() {
if(xhr_object.readyState == 1)
{
xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr_object.send(
"arg1="+document.getElementById("arg1").value+
"&&arg2="+document.getElementById("arg2").value
);
}
else if(xhr_object.readyState == 4)
{
document.getElementById("result").value = xhr_object.responseText;
}
xhr_object.open("POST","add.php",true);
}
}
</script>
</head>
<body>
<input type="text" size="3" id="arg1" value="0" onChange="maj()" />
<input type="text" size="3" id="arg2" value="0" onChange="maj()" />
<input type="text" size="5" id="arg3" value="0" />
</body>
</html>[/php]
Et dans add.php :
[php]<?php
$arg1 = isset($_POST['arg1'])?intval($_POST['arg1']):0;
$arg2 = isset($_POST['arg2'])?intval($_POST['arg2']):0;
echo ($arg1+$arg2);
?>[/php]
C'est un exemple, je n'ai pas testé, mais moralement c'est bon...