Test.html
Copy codeThe Code is as follows:
<Label onclick = "javascript: post_data ();"> click </label>
Function ajax_init ()
{
Var ajax = false;
Try {
Ajax = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Ajax = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (E ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = 'Undefined '){
Ajax = new XMLHttpRequest ();
}
Return ajax;
}
Function post_data ()
{
Var url = "/server/xml. php ";
Var show_check = document. getElementById ("show_check ");
Var show_flag = document. getElementById ("show_flag ");
Var ajax = ajax_init ();
Ajax. open ("GET", url, true );
// Var img = " ";
Ajax. onreadystatechange = function ()
{
If (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; // wuddy
// Alert ("responseXML's value:" + info [0]. firstChild. data );
}
/* Else
{
Show. innerHTML = img;
}*/
}
Ajax. send (null );
}
Json. php
Copy codeThe Code is as follows:
<? Php
/* If $ info = array ('no1' => 'bsd', 'no2 '=> 'wuddy', 'no3' => 'xie') is written here ');*/
/* Similarly, the html file must be var show_info = eval ('[' + ret + ']'); all return an object */
$ Info = array ('no1' => 'bsd', 'no2 '=> 'wuddy', 'no3' => 'xie '));
$ Userinfo = json_encode ($ info );
Echo $ userinfo;
?>