javascript Ajax获取远程url的返回判断
时间:2020-12-27 16:42:53|栏目:JavaScript代码|点击: 次
复制代码 代码如下:
<SCRIPT LANGUAGE="JavaScript">
<!--
function ajaxByJyking(){
var xmlhttp_request = "";
try{
if( window.ActiveXObject ){
for( var i = 5; i; i-- ){
try{
if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" ); }
else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
xmlhttp_request.setRequestHeader("Content-Type","text/xml");
xmlhttp_request.setRequestHeader("Charset","gb2312"); }
break;}
catch(e){
xmlhttp_request = false; } } }
else if( window.XMLHttpRequest )
{ xmlhttp_request = new XMLHttpRequest();
if (xmlhttp_request.overrideMimeType)
{ xmlhttp_request.override.MimeType('text/xml'); } } }
catch(e){ xmlhttp_request = false; }
xmlhttp_request.open('GET', 'https://www.jb51.net', true);
xmlhttp_request.send(null);
xmlhttp_request.onreadystatechange = function(){
if (xmlhttp_request.readyState == 4) {
// 收到完整的服务器响应
document.write("yes")
} else{
alert(1)
}
}
}
ajaxByJyking();
//-->
</SCRIPT>
栏 目:JavaScript代码
下一篇:基于JavaScript中字符串的match与replace方法(详解)
本文标题:javascript Ajax获取远程url的返回判断
本文地址:http://www.codeinn.net/misctech/37178.html