发送异步请求。(此方法是为兼容 prototype.js 而写,调用风格与 prototype 一致)
当前使用的 xmlhttp 对象。
发送异步请求,并返回 xmlhttp 对象,该对象内置有 abort() 方法,用于提前终止请求。异步请求成功则执行 onComplete,失败则执行 onError 。并返回 xmlhttp 对象。
Ajax.Request 是个接口完整的 Ajax 方法,是 myJSFrame 中所有其他 Ajax 方法的核心方法。
示例一:
<script type="text/javascript" >
var
myAjax = new Ajax.Request(
"http://www.happyshow.org/form.asp",
{
method:"post", //表单提交方式
parameters:"name=acai&age=26&sex=male", //提交的表单数据
setRequestHeader:{"If-Modified-Since":"0"}, //禁止读取缓存数据
onComplete:function(x){ //提交成功回调
alert(x.responseText);
},
onError:function(x){ //提交失败回调
alert(x.statusText);
}
}
);
</script>
示例二:
<script type="text/javascript" >
var xmlString = "<root>"
+"<people><name>caizhongqi</name><sex>male</sex></people>"
+"<people><name>ahuang</name><sex>female</sex></people>"
+" </root>";
var
myAjax = new Ajax.Request(
"http://www.happyshow.org/xmlform.asp",
{
method:"post", //表单提交方式
postBody:xmlString, //提交的xml
setRequestHeader:{"content-Type":"text/xml"}, //指定发送的数据为 xml 文档(非字符串)
onComplete:function(x){ //提交成功回调
alert(x.responseXML.xml);
},
onError:function(x){ //提交失败回调
alert(x.statusText);
}
}
);
</script>