/-----------test.html---------------/
<label onclick="javascript:post_data();">klik </label>
fungsi ajax_init()
{
var ajax=salah;
mencoba {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} tangkapan (e) {
mencoba {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} tangkapan (E) {
ajax = salah;
}
}
if (!ajax && typeof XMLHttpRequest!='tidak terdefinisi') {
ajax = XMLHttpRequest baru();
}
kembali ajax;
}
fungsi post_data()
{
var url = "/server/xml.php";
var show_check = dokumen.getElementById("show_check");
var show_flag = dokumen.getElementById("show_flag");
var ajax = ajax_init();
ajax.open("DAPATKAN", url, benar);
//var img = "<img src='/img/loading.gif'>";
ajax.onreadystatechange = fungsi()
{
jika (ajax.readyState == 4 && ajax.status == 200)
{
var ret = ajax.responseText;
var show_info = eval(ret);
show_check.innerHTML = show_info[0].no1; // bsd
show_flag.innerHTML = show_info[0].no2; // tidak jelas
//alert("nilai responeXML: " + info[0].firstChild.data);
}
/*kalau tidak
{
tampilkan.innerHTML = img;
}*/
}
ajax.kirim(null);
}
/*------------json.php---*/
<?php
/* 这边如果写成 $info = array('no1'=>'bsd', 'no2'=>'wuddy', 'no3'=>'xie'); */
/* 同样要把html文件中必成 var show_info = eval('[' + ret + ']'); 都是返回一个对象 */
$info = array(array('no1'=>'bsd', 'no2'=>'wuddy', 'no3'=>'xie'));
$info pengguna = json_encode($info);
echo $informasi pengguna;
?>