function _post(Url,Args) { var xmlhttp; var error; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else if(typeof ActiveXObject != "undefined"){ eval('try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {xmlhttp = null;error=e;}'); } if(typeof(Args)=='undefined'){ Args = 'null=true';} if(null != xmlhttp) { xmlhttp.open("POST",Url,false); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.send(Args); strText = xmlhttp.responseText; } return strText; }使用方法很简单,方法如下: <script language="javascript"> var data = _post("ajax.PHP"); alert(data); </script> 这样,_post函数返回了ajax.PHP的输出结果。 ajax.PHP页面的内容大致可以这样写: <?PHP header("Content-type: text/xml; charset=gb2312"); echo 'This a string.'; ?> 这样就写成了一个简单的AJAX应用,当然,上述_post函数可以完成更多功能,如有需要可以留言。 需要注意的是AJAX的编码问题。一般像上面这样发送一个HTTP头信息即可,如:header("Content-type: text/xml; charset=gb2312");