<script> alert("send"); postSend();
var _returnValues; function postSend() { var fd = new FormData(); fd.append('foo'‚1); fd.append('bar'‚'a'); var xhr = new XMLHttpRequest(); xhr.open('POST'‚'retdata.php'); xhr.send(fd); xhr.onreadystatechange = function(){ if ((xhr.readyState == 4) && (xhr.status==200)) { alert("ok"); //alert(xhr.responseText); _returnValues = JSON.parse(xhr.responseText); alert(_returnValues); } }; } </script>
PHP
<?php //foobar.php $foo = isset($_POST['foo']) ? $_POST['foo']:null; $bar = isset($_POST['bar']) ? $_POST['bar']:null; $result = "test".$foo.":".$bar;//何らかの処理 //print $result; print json_encode($result); ?>
|