网址:http://www.xiaojb.com/archives/it/javascripthttp.shtml
javascript代码如下:
function jb()
{
var A=null;
try
{
A=new ActiveXObject(”Msxml2.XMLHTTP”)
} catch(e) {
try
{
A=new ActiveXObject(”Microsoft.XMLHTTP”)
} catch(oc) {
A=null
}
}
if ( !A && typeof XMLHttpRequest != “undefined” )
{
A=new XMLHttpRequest()
}
return A
}
var ajaxObj;
ajaxObj = jb();
if(ajaxObj){
var url = “test.html”;
ajaxObj.onreadystatechange = function() {
if (ajaxObj.readyState == 4) {
if (ajaxObj.status == 200) {
alert(ajaxObj.responseText);
} else {
alert(’error’);
alert(ajaxObj.responseText);
}
}
}
ajaxObj.open(’GET’, url, true);
ajaxObj.send(null);
}
学习的过程中发现几点:
1 url不能使用其他的domain,比如我用了http://www.xiaojb.com/xxx.html,结果提示没有权限使用XMLHttpRequest.open
2 XMLHttpRequest.send()必须有参数,如果没有可以使用XMLHttpRequest.send(null);
3 XMLHttpRequest.open(method,url,flag)中如果flag为false,则不调用XMLHttpRequest.onreadystatechange()
4 POST的方法是XMLHttpRequest.open(’POST’,url,true’),XMLHttpRequest.send(”username=xxx”);
其他学习的连接
http://blog.blueshop.com.tw/ajun/archive/2005/04/26/3402.aspx
http://developer.apple.com/internet/webcontent/xmlhttpreq.html
更多的去搜索XMLHttpRequest
补:后来在学习的过程中发现,XMLHttpRequest.send在ie下是可以使用XMLHttpRequest.send()的,而firefox只能使用XMLHttpRequest.send(null)

May 19th, 2006 at 16:21
你好,请问你调试js用什么环境,调试方法是什么?谢谢!
May 19th, 2006 at 17:24
我使用firefox的java控制台调试,结合tamper data插件。