私は以下のようなAJAX関数を持っています:
function ajx(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
// alert(ajaxRequest.readyState);
if(ajaxRequest.readyState == 4){
//alert(ajaxRequest.responseText);
var res = ajaxRequest.responseText;
var a = JSON.parse(res);
var v1 = a[0];
var v2 = a[1];
var v3 = a[2];
//alert(v1);
document.getElementById('vara').value = v1;
document.getElementById('varb').value = v2;
document.getElementById('varc').value = v3;
}
}
ajaxRequest.open("GET", "ajax.php", true);
ajaxRequest.send(null); }
現在が存在するHTML id
:
<div id="vara"></div>
<div id="varb"></div>
<div id="varc"></div>
対応するajax.php
ものは次のとおりです。
<?php
$resp = array('man','cow','dog');
echo json_encode($resp);
?>
アラートを出すv1
v2
か、それぞれ、、 とv3
表示される場合。しかし、それはHTMLで値を出力していません。どうしたの?man
cow
dog