AJAX 常用函数
程序员文章站
2022-07-02 16:50:13
创建xmlhttp对象,区别ie,mozilla浏览器 复制代码 代码如下: function getre...
创建xmlhttp对象,区别ie,mozilla浏览器
复制代码 代码如下:
function getrequest() {
http_request = false;
if (window.xmlhttprequest) {
//对于mozilla﹑netscape﹑safari等浏览器,创建xmlhttprequest
http_request = new xmlhttprequest();
if (http_request.overridemimetype) {
//如果服务器响应的header不是text/xml,可以调用其它方法修改该header
http_request.overridemimetype('text/xml');
}
} else if (window.activexobject) {
// 对于internet explorer浏览器,创建xmlhttprequest
try {
http_request = new activexobject("msxml2.xmlhttp");
} catch (e) {
try {
http_request = new activexobject("microsoft.xmlhttp");
} catch (e) {}
}
}
return http_request;
}
//获得url 的responsetext http_request = false;
if (window.xmlhttprequest) {
//对于mozilla﹑netscape﹑safari等浏览器,创建xmlhttprequest
http_request = new xmlhttprequest();
if (http_request.overridemimetype) {
//如果服务器响应的header不是text/xml,可以调用其它方法修改该header
http_request.overridemimetype('text/xml');
}
} else if (window.activexobject) {
// 对于internet explorer浏览器,创建xmlhttprequest
try {
http_request = new activexobject("msxml2.xmlhttp");
} catch (e) {
try {
http_request = new activexobject("microsoft.xmlhttp");
} catch (e) {}
}
}
return http_request;
}
复制代码 代码如下:
function getresponsetext(url)
{
http_request=getrequest();
http_request.open('get', url, false);
http_request.send(null);
if (http_request.readystate == 4)
{
// 收到完整的服务器响应
if (http_request.status == 200) {
//http服务器响应的值ok
requestdoc = http_request.responsetext;
//将服务器返回的字符串写到页面中id为message的区域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}
//获得url 的responsexml {
http_request=getrequest();
http_request.open('get', url, false);
http_request.send(null);
if (http_request.readystate == 4)
{
// 收到完整的服务器响应
if (http_request.status == 200) {
//http服务器响应的值ok
requestdoc = http_request.responsetext;
//将服务器返回的字符串写到页面中id为message的区域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}
复制代码 代码如下:
function getresponsetext(url)
{
http_request=getrequest();
http_request.open('get', url, false);
http_request.send(null);
if (http_request.readystate == 4)
{
// 收到完整的服务器响应
if (http_request.status == 200) {
//http服务器响应的值ok
requestdoc = http_request.responsexml;
//将服务器返回的字符串写到页面中id为message的区域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}
{
http_request=getrequest();
http_request.open('get', url, false);
http_request.send(null);
if (http_request.readystate == 4)
{
// 收到完整的服务器响应
if (http_request.status == 200) {
//http服务器响应的值ok
requestdoc = http_request.responsexml;
//将服务器返回的字符串写到页面中id为message的区域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}
上一篇: 第一个Spring程序(DI的实现)