- -简单的Ajax搜索
<html>
<script language="javascript" type="text/javascript">
function AJAXRequest() {
var xmlObj = false;
var CBfunc,ObjSelf;
ObjSelf=this;
try { xmlObj=new XMLHttpRequest; }
catch(e) {
try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
catch(e2) {
try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e3) { xmlObj=false; }
}
}
if (!xmlObj) return false;
this.method="POST";
this.url;
this.async=true;
this.content="";
this.callback=function(cbobj) {return;}
this.send=function() {
if(!this.method||!this.url||!this.async) return false;
xmlObj.open (this.method, this.url, this.async);
if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlObj.onreadystatechange=function() {
if(xmlObj.readyState==4) {
if(xmlObj.status==200) {
ObjSelf.callback(xmlObj);
}
}
}
if(this.method=="POST") xmlObj.send(this.content);
else xmlObj.send(null);
}
}
function Google()
{
var v=new AJAXRequest();
var ajaxobj=new AJAXRequest; // 创建AJAX对象
ajaxobj.method="GET"; // 设置请求方式为GET
ajaxobj.url="http://www.google.cn/search?q="+document.getElementById("cc").value // URL为default.asp
// 设置回调函数,输出响应内容
ajaxobj.callback=function(xmlobj) {
// document.write(xmlobj.responseText);
if (xmlobj.readyState == 4)
{
if( xmlobj.status == 200)
{
document.getElementById('Content').innerHTML = xmlobj.responseText;
}
}
}
ajaxobj.send(); // 发送请求
}
</script>
<body>
<input id="cc" /><input type="button" value="搜索Google" name="B3" onclick="Google()"/>
<div id="Content"/>
</form>
</body>
</html>
<script language="javascript" type="text/javascript">
function AJAXRequest() {
var xmlObj = false;
var CBfunc,ObjSelf;
ObjSelf=this;
try { xmlObj=new XMLHttpRequest; }
catch(e) {
try { xmlObj=new ActiveXObject("MSXML2.XMLHTTP"); }
catch(e2) {
try { xmlObj=new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e3) { xmlObj=false; }
}
}
if (!xmlObj) return false;
this.method="POST";
this.url;
this.async=true;
this.content="";
this.callback=function(cbobj) {return;}
this.send=function() {
if(!this.method||!this.url||!this.async) return false;
xmlObj.open (this.method, this.url, this.async);
if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlObj.onreadystatechange=function() {
if(xmlObj.readyState==4) {
if(xmlObj.status==200) {
ObjSelf.callback(xmlObj);
}
}
}
if(this.method=="POST") xmlObj.send(this.content);
else xmlObj.send(null);
}
}
function Google()
{
var v=new AJAXRequest();
var ajaxobj=new AJAXRequest; // 创建AJAX对象
ajaxobj.method="GET"; // 设置请求方式为GET
ajaxobj.url="http://www.google.cn/search?q="+document.getElementById("cc").value // URL为default.asp
// 设置回调函数,输出响应内容
ajaxobj.callback=function(xmlobj) {
// document.write(xmlobj.responseText);
if (xmlobj.readyState == 4)
{
if( xmlobj.status == 200)
{
document.getElementById('Content').innerHTML = xmlobj.responseText;
}
}
}
ajaxobj.send(); // 发送请求
}
</script>
<body>
<input id="cc" /><input type="button" value="搜索Google" name="B3" onclick="Google()"/>
<div id="Content"/>
</form>
</body>
</html>
ajax部分用的是Site: http://www.xujiwei.cn/