javascript之Ajax

function GetJson()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try {
xmlHttp = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
try {
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e) {
alert(“您的浏览器不支持AJAX!”);
return false;
}
}
}

xmlHttp.onreadystatechange = function()
{
if (xmlHttp.readyState == 4)
{
//alert(xmlHttp.responseText);
var str = xmlHttp.responseText;
document.getElementById(‘show’).innerHTML +=str;
//alert(str);
var obj = eval(‘(‘+ xmlHttp.responseText +’)’);
//var obj = eval(({“id”:”123″,”name”:”elar”,”age”:”21″}));
alert(obj.name);
}
}
var data = {id:’1′,name:’你好’};
var json_s = “json=”+JSON.stringify(data);
xmlHttp.open(“POST”, “getJSON.php”, true);
xmlHttp.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded”);
xmlHttp.send(json_s);
//alert(json_s);
}