10/10/2018, 09:49
Hỏi về module thời tiết của vnexpress.net
Em chào các anh em trên diễn đàn, em mới lấy về cái module thời tiết của vnexpress, em chạy trên ie thì ok nhưng mà chạy trên firefox thì ko được, thứ 2 nữa là em chạy trên máy tính của em ở 1 ổ nào đó thì chạy được vd như: c:\a.html nhưng mà chạy trên máy chủ hoặc chạy trên localhost thì ko chạy được toàn báo lỗi, ko hiểu sao nữa vd như:
http://abc.com/a.html
hoặc http://localhost/a/a.html
2 cái trên thì ko chạy được nhưng vất vào 1 ổ nào đó và chạy trực tiếp thì ok, rất mong anh em giúp đỡ sớm, đoạn code em pase ở dưới, đó là 1 trang, anh em copy rồi pase vào 1 file html rồi test hộ em nhé, thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>VnExpress - Daily News</title>
<link rel="stylesheet" href="a/default.css" type="text/css" />
<script type="text/javascript">
//-------------------------------------begin AjaxRequest ----------
function AjaxRequest(){var req =new Object();
req.timeout =null;
req.generateUniqueUrl = false;
req.url =window.location.href;
req.method ="GET";
req.async =true;
req.username =null;
req.password =null;
req.parameters =new Object();
req.requestIndex =AjaxRequest.numAjaxRequests++;
req.responseReceived =false;
req.groupName =null;
req.queryString ="";
req.responseText =null;
req.respon***ML =null;
req.status =null;
req.statusText =null;
req.aborted =false;
req.xmlHttpRequest =null;
req.onTimeout=null;
req.onLoading=null;
req.onLoaded=null;
req.onInteractive=null;
req.onComplete=null;
req.onSuccess=null;
req.onError=null;
req.onGroupBegin=null;
req.onGroupEnd=null;
req.xmlHttpRequest = AjaxRequest.getXmlHttpRequest();
if(req.xmlHttpRequest==null){return null;}req.xmlHttpRequest.onreadystatechange =
function(){if(req==null || req.xmlHttpRequest==null){return;}if(req.xmlHttpRe quest.readyState==1){req.onLoadingInternal(req);}i f(req.xmlHttpRequest.readyState==2){req.onLoadedIn ternal(req);}if(req.xmlHttpRequest.readyState==3){ req.onInteractiveInternal(req);}if(req.xmlHttpRequ est.readyState==4){req.onCompleteInternal(req);}};
req.onLoadingInternalHandled=false;
req.onLoadedInternalHandled=false;
req.onInteractiveInternalHandled=false;
req.onCompleteInternalHandled=false;
req.onLoadingInternal=
function(){if(req.onLoadingInternalHandled){return ;}AjaxRequest.numActiveAjaxRequests++;
if(AjaxRequest.numActiveAjaxRequests==1 && typeof(window['AjaxRequestBegin'])=="function"){AjaxRequestBegin();}if(req.groupNam e!=null){if(typeof(AjaxRequest.numActiveAjaxGroupR equests[req.groupName])=="undefined"){AjaxRequest.numActiveAjaxGroupRequ ests[req.groupName] =0;}AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==1 && typeof(req.onGroupBegin)=="function"){req.onGroupB egin(req.groupName);}}if(typeof(req.onLoading)=="f unction"){req.onLoading(req);}req.onLoadingInterna lHandled=true;};
req.onLoadedInternal=
function(){if(req.onLoadedInternalHandled){return; }if(typeof(req.onLoaded)=="function"){req.onLoaded (req);}req.onLoadedInternalHandled=true;};
req.onInteractiveInternal=
function(){if(req.onInteractiveInternalHandled){re turn;}if(typeof(req.onInteractive)=="function"){re q.onInteractive(req);}req.onInteractiveInternalHan dled=true;};
req.onCompleteInternal=
function(){if(req.onCompleteInternalHandled || req.aborted){return;}req.onCompleteInternalHandled =true;
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(r eq.groupName!=null){AjaxRequest.numActiveAjaxGroup Requests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd (req.groupName);}}req.responseReceived =true;
req.status =req.xmlHttpRequest.status;
req.statusText =req.xmlHttpRequest.statusText;
req.responseText =req.xmlHttpRequest.responseText;
req.respon***ML =req.xmlHttpRequest.respon***ML;
if(typeof(req.onComplete)=="function"){req.onCompl ete(req);}if(req.xmlHttpRequest.status==200 && typeof(req.onSuccess)=="function"){req.onSuccess(r eq);}else if(typeof(req.onError)=="function"){req.onError(re q);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;};
req.onTimeoutInternal=
function(){if(req!=null && req.xmlHttpRequest!=null && !req.onCompleteInternalHandled){req.aborted =true;
req.xmlHttpRequest.abort();
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(r eq.groupName!=null){AjaxRequest.numActiveAjaxGroup Requests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd (req.groupName);}}if(typeof(req.onTimeout)=="funct ion"){req.onTimeout(req);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;}};
req.process = function()
{
if(req.xmlHttpRequest!=null)
{
if(req.generateUniqueUrl && req.method=="GET")
{
req.parameters["AjaxRequestUniqueId"] =new Date().getTime() + "" + req.requestIndex;
}
var content =null;
for(var i in req.parameters)
{
if(req.queryString.length>0)
{
req.queryString +="&";
}
req.queryString +=encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]);
}
if(req.method=="GET")
{
if(req.queryString.length>0)
{
req.url +=((req.url.indexOf("?")>-1)?"&":"?") + req.queryString;
}
}
req.xmlHttpRequest.open(req.method,req.url,req.asy nc);
if(req.method=="POST")
{
if(typeof(req.xmlHttpRequest.setRequestHeader)!="u ndefined")
{
req.xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
content =req.queryString;
}
if(req.timeout>0)
{
setTimeout(req.onTimeoutInternal,req.timeout);
}
req.xmlHttpRequest.send(content);
}
};
req.handleArguments =
function(args){for(var i in args){if(typeof(req[i])=="undefined"){req.parameters[i] =args[i];}else{req[i] =args[i];}}};
req.getAllResponseHeaders =
function(){if(req.xmlHttpRequest!=null){if(req.res ponseReceived){return req.xmlHttpRequest.getAllResponseHeaders();}alert( "Cannot getAllResponseHeaders because a response has not yet been received");}};
req.getResponseHeader =
function(headerName){if(req.xmlHttpRequest!=null){ if(req.responseReceived){return req.xmlHttpRequest.getResponseHeader(headerName);} alert("Cannot getResponseHeader because a response has not yet been received");}};
return req;}AjaxRequest.getXmlHttpRequest =function(){if(window.XMLHttpRequest){return new XMLHttpRequest();}else if(window.ActiveXObject){/*@cc_on @*/
/*@if(@_jscript_version >=5)
try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{retu rn new ActiveXObject("Microsoft.XMLHTTP");}catch(E){retur n null;}}@end @*/}else{return null;}};
AjaxRequest.isActive =function(){return(AjaxRequest.numActiveAjaxReques ts>0);};
AjaxRequest.get =function(args){AjaxRequest.doRequest("GET",args); };
AjaxRequest.post =function(args){AjaxRequest.doRequest("POST",args) ;};
AjaxRequest.doRequest =function(method,args){if(typeof(args)!="undefined " && args!=null){var myRequest =new AjaxRequest();
myRequest.method =method;
myRequest.handleArguments(args);
myRequest.process();}};
AjaxRequest.submit =function(theform, args){var myRequest =new AjaxRequest();
if(myRequest==null){return false;}var serializedForm =AjaxRequest.serializeForm(theform);
myRequest.method =theform.method.toUpperCase();
myRequest.url =theform.action;
myRequest.handleArguments(args);
myRequest.queryString =serializedForm;
myRequest.process();
return true;};
AjaxRequest.serializeForm =function(theform){var els =theform.elements;
var len =els.length;
var queryString ="";
this.addField =
function(name,value){if(queryString.length>0){quer yString +="&";}queryString +=encodeURIComponent(name) + "=" + encodeURIComponent(value);};
for(var i=0;i<len;i++){var el =els[i];
if(!el.disabled){switch(el.type){case 'text': case 'password': case 'hidden': case 'textarea':
this.addField(el.name,el.value);
break;
case 'select-one':
if(el.selectedIndex>=0){this.addField(el.name,el.o ptions[el.selectedIndex].value);}break;
case 'select-multiple':
for(var j=0;j<el.options.length;j++){if(el.options[j].selected){this.addField(el.name,el.options[j].value);}}break;
case 'checkbox': case 'radio':
if(el.checked){this.addField(el.name,el.value);}br eak;}}}return queryString;};
AjaxRequest.numActiveAjaxRequests =0;
AjaxRequest.numActiveAjaxGroupRequests =new Object();
AjaxRequest.numAjaxRequests =0;
//-------------------------------end Ajaxrequest ----------------------------------------
function ShowWeatherBox(vId)
{
var sLink = ';
sLink = 'http://www.vnexpress.net/ListFile/Weather/';
switch (parseInt(vId)){
case 1: sLink = sLink.concat('Sonla.xml');break;
case 2: sLink = sLink.concat('Viettri.xml');break;
case 3: sLink = sLink.concat('Haiphong.xml');break;
case 4: sLink = sLink.concat('Hanoi.xml');break;
case 5: sLink = sLink.concat('Vinh.xml');break;
case 6: sLink = sLink.concat('Danang.xml');break;
case 7: sLink = sLink.concat('Nhatrang.xml');break;
case 8: sLink = sLink.concat('Pleicu.xml');break;
case 9: sLink = sLink.concat('HCM.xml');break;
default: sLink = sLink.concat('Hanoi.xml');break;
}
AjaxRequest.get(
{
'url':sLink
,'onSuccess':function(req){
var vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather;
vAdImg = req.respon***ML.getElementsByTagName('AdImg').item (0).firstChild.nodeValue;
vAdImg1 = req.respon***ML.getElementsByTagName('AdImg1').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg2'). item(0).firstChild != null)
vAdImg2 = req.respon***ML.getElementsByTagName('AdImg2').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg3'). item(0).firstChild != null)
vAdImg3 = req.respon***ML.getElementsByTagName('AdImg3').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg4'). item(0).firstChild != null)
vAdImg4 = req.respon***ML.getElementsByTagName('AdImg4').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg5'). item(0).firstChild != null)
vAdImg5 = req.respon***ML.getElementsByTagName('AdImg5').ite m(0).firstChild.nodeValue;
vWeather = req.respon***ML.getElementsByTagName('Weather').it em(0).firstChild.nodeValue;
GetWeatherBox(vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather);
}
,'onError':function(req){}
}
)
}
function GetWeatherBox(vImg, vImg1, vImg2, vImg3, vImg4, vImg5, vWeather){
var sHTML = ';
sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg).concat('" class="img-weather" alt="" /> ');
sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg1).concat('" class="img-weather" alt="" />');
if(vImg2!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg2).concat('" class="img-weather" alt="" />');
if(vImg3!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg3).concat('" class="img-weather" alt="" />');
if(vImg4!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg4).concat('" class="img-weather" alt="" />');
if(vImg5!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg5).concat('" class="img-weather" alt="" />');
sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" />');
gmobj('img-Do').innerHTML = sHTML;
gmobj('txt-Weather').innerHTML = vWeather;
}
function gmobj(o)
{
if(document.getElementById){ m=document.getElementById(o); }
else if(document.all){ m=document.all[o]; }
else if(document.layers){ m=document[o]; }
return m;
}
</script>
</head>
<body>
<form id="frmWeather" method="post" action="#">
<p>
<select id="cboWeather" class="slt-weather" onchange="ShowWeatherBox(this.value);">
<option value="1">Sơn La</option>
<option value="3">Hải Phòng</option>
<option value="4" selected="selected">Hà Nội</option>
<option value="5">Vinh</option>
<option value="6">Đà Nẵng</option>
<option value="7">Nha Trang</option>
<option value="8">Pleiku</option>
<option value="9">TP HCM</option>
</select>
</p>
<p id="img-Do"><img src="http://www.vnexpress.net/Images/Weather/i_nhieumay.gif" class="img-weather" alt="" /> <img src="http://www.vnexpress.net/Images/Weather/2.gif" class="img-weather" alt="" /><img src="http://www.vnexpress.net/Images/Weather/6.gif" class="img-weather" alt="" /><img src="http://www.vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" /></p>
<p id="txt-Weather"><b>Không mưa</b><br>Độ ẩm 91%<br>Lặng gió</p>
<script type="text/javascript" language="javascript">ShowWeatherBox(4);</script>
</form>
</body>
</html>
http://abc.com/a.html
hoặc http://localhost/a/a.html
2 cái trên thì ko chạy được nhưng vất vào 1 ổ nào đó và chạy trực tiếp thì ok, rất mong anh em giúp đỡ sớm, đoạn code em pase ở dưới, đó là 1 trang, anh em copy rồi pase vào 1 file html rồi test hộ em nhé, thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>VnExpress - Daily News</title>
<link rel="stylesheet" href="a/default.css" type="text/css" />
<script type="text/javascript">
//-------------------------------------begin AjaxRequest ----------
function AjaxRequest(){var req =new Object();
req.timeout =null;
req.generateUniqueUrl = false;
req.url =window.location.href;
req.method ="GET";
req.async =true;
req.username =null;
req.password =null;
req.parameters =new Object();
req.requestIndex =AjaxRequest.numAjaxRequests++;
req.responseReceived =false;
req.groupName =null;
req.queryString ="";
req.responseText =null;
req.respon***ML =null;
req.status =null;
req.statusText =null;
req.aborted =false;
req.xmlHttpRequest =null;
req.onTimeout=null;
req.onLoading=null;
req.onLoaded=null;
req.onInteractive=null;
req.onComplete=null;
req.onSuccess=null;
req.onError=null;
req.onGroupBegin=null;
req.onGroupEnd=null;
req.xmlHttpRequest = AjaxRequest.getXmlHttpRequest();
if(req.xmlHttpRequest==null){return null;}req.xmlHttpRequest.onreadystatechange =
function(){if(req==null || req.xmlHttpRequest==null){return;}if(req.xmlHttpRe quest.readyState==1){req.onLoadingInternal(req);}i f(req.xmlHttpRequest.readyState==2){req.onLoadedIn ternal(req);}if(req.xmlHttpRequest.readyState==3){ req.onInteractiveInternal(req);}if(req.xmlHttpRequ est.readyState==4){req.onCompleteInternal(req);}};
req.onLoadingInternalHandled=false;
req.onLoadedInternalHandled=false;
req.onInteractiveInternalHandled=false;
req.onCompleteInternalHandled=false;
req.onLoadingInternal=
function(){if(req.onLoadingInternalHandled){return ;}AjaxRequest.numActiveAjaxRequests++;
if(AjaxRequest.numActiveAjaxRequests==1 && typeof(window['AjaxRequestBegin'])=="function"){AjaxRequestBegin();}if(req.groupNam e!=null){if(typeof(AjaxRequest.numActiveAjaxGroupR equests[req.groupName])=="undefined"){AjaxRequest.numActiveAjaxGroupRequ ests[req.groupName] =0;}AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==1 && typeof(req.onGroupBegin)=="function"){req.onGroupB egin(req.groupName);}}if(typeof(req.onLoading)=="f unction"){req.onLoading(req);}req.onLoadingInterna lHandled=true;};
req.onLoadedInternal=
function(){if(req.onLoadedInternalHandled){return; }if(typeof(req.onLoaded)=="function"){req.onLoaded (req);}req.onLoadedInternalHandled=true;};
req.onInteractiveInternal=
function(){if(req.onInteractiveInternalHandled){re turn;}if(typeof(req.onInteractive)=="function"){re q.onInteractive(req);}req.onInteractiveInternalHan dled=true;};
req.onCompleteInternal=
function(){if(req.onCompleteInternalHandled || req.aborted){return;}req.onCompleteInternalHandled =true;
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(r eq.groupName!=null){AjaxRequest.numActiveAjaxGroup Requests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd (req.groupName);}}req.responseReceived =true;
req.status =req.xmlHttpRequest.status;
req.statusText =req.xmlHttpRequest.statusText;
req.responseText =req.xmlHttpRequest.responseText;
req.respon***ML =req.xmlHttpRequest.respon***ML;
if(typeof(req.onComplete)=="function"){req.onCompl ete(req);}if(req.xmlHttpRequest.status==200 && typeof(req.onSuccess)=="function"){req.onSuccess(r eq);}else if(typeof(req.onError)=="function"){req.onError(re q);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;};
req.onTimeoutInternal=
function(){if(req!=null && req.xmlHttpRequest!=null && !req.onCompleteInternalHandled){req.aborted =true;
req.xmlHttpRequest.abort();
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(r eq.groupName!=null){AjaxRequest.numActiveAjaxGroup Requests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd (req.groupName);}}if(typeof(req.onTimeout)=="funct ion"){req.onTimeout(req);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;}};
req.process = function()
{
if(req.xmlHttpRequest!=null)
{
if(req.generateUniqueUrl && req.method=="GET")
{
req.parameters["AjaxRequestUniqueId"] =new Date().getTime() + "" + req.requestIndex;
}
var content =null;
for(var i in req.parameters)
{
if(req.queryString.length>0)
{
req.queryString +="&";
}
req.queryString +=encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]);
}
if(req.method=="GET")
{
if(req.queryString.length>0)
{
req.url +=((req.url.indexOf("?")>-1)?"&":"?") + req.queryString;
}
}
req.xmlHttpRequest.open(req.method,req.url,req.asy nc);
if(req.method=="POST")
{
if(typeof(req.xmlHttpRequest.setRequestHeader)!="u ndefined")
{
req.xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
content =req.queryString;
}
if(req.timeout>0)
{
setTimeout(req.onTimeoutInternal,req.timeout);
}
req.xmlHttpRequest.send(content);
}
};
req.handleArguments =
function(args){for(var i in args){if(typeof(req[i])=="undefined"){req.parameters[i] =args[i];}else{req[i] =args[i];}}};
req.getAllResponseHeaders =
function(){if(req.xmlHttpRequest!=null){if(req.res ponseReceived){return req.xmlHttpRequest.getAllResponseHeaders();}alert( "Cannot getAllResponseHeaders because a response has not yet been received");}};
req.getResponseHeader =
function(headerName){if(req.xmlHttpRequest!=null){ if(req.responseReceived){return req.xmlHttpRequest.getResponseHeader(headerName);} alert("Cannot getResponseHeader because a response has not yet been received");}};
return req;}AjaxRequest.getXmlHttpRequest =function(){if(window.XMLHttpRequest){return new XMLHttpRequest();}else if(window.ActiveXObject){/*@cc_on @*/
/*@if(@_jscript_version >=5)
try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{retu rn new ActiveXObject("Microsoft.XMLHTTP");}catch(E){retur n null;}}@end @*/}else{return null;}};
AjaxRequest.isActive =function(){return(AjaxRequest.numActiveAjaxReques ts>0);};
AjaxRequest.get =function(args){AjaxRequest.doRequest("GET",args); };
AjaxRequest.post =function(args){AjaxRequest.doRequest("POST",args) ;};
AjaxRequest.doRequest =function(method,args){if(typeof(args)!="undefined " && args!=null){var myRequest =new AjaxRequest();
myRequest.method =method;
myRequest.handleArguments(args);
myRequest.process();}};
AjaxRequest.submit =function(theform, args){var myRequest =new AjaxRequest();
if(myRequest==null){return false;}var serializedForm =AjaxRequest.serializeForm(theform);
myRequest.method =theform.method.toUpperCase();
myRequest.url =theform.action;
myRequest.handleArguments(args);
myRequest.queryString =serializedForm;
myRequest.process();
return true;};
AjaxRequest.serializeForm =function(theform){var els =theform.elements;
var len =els.length;
var queryString ="";
this.addField =
function(name,value){if(queryString.length>0){quer yString +="&";}queryString +=encodeURIComponent(name) + "=" + encodeURIComponent(value);};
for(var i=0;i<len;i++){var el =els[i];
if(!el.disabled){switch(el.type){case 'text': case 'password': case 'hidden': case 'textarea':
this.addField(el.name,el.value);
break;
case 'select-one':
if(el.selectedIndex>=0){this.addField(el.name,el.o ptions[el.selectedIndex].value);}break;
case 'select-multiple':
for(var j=0;j<el.options.length;j++){if(el.options[j].selected){this.addField(el.name,el.options[j].value);}}break;
case 'checkbox': case 'radio':
if(el.checked){this.addField(el.name,el.value);}br eak;}}}return queryString;};
AjaxRequest.numActiveAjaxRequests =0;
AjaxRequest.numActiveAjaxGroupRequests =new Object();
AjaxRequest.numAjaxRequests =0;
//-------------------------------end Ajaxrequest ----------------------------------------
function ShowWeatherBox(vId)
{
var sLink = ';
sLink = 'http://www.vnexpress.net/ListFile/Weather/';
switch (parseInt(vId)){
case 1: sLink = sLink.concat('Sonla.xml');break;
case 2: sLink = sLink.concat('Viettri.xml');break;
case 3: sLink = sLink.concat('Haiphong.xml');break;
case 4: sLink = sLink.concat('Hanoi.xml');break;
case 5: sLink = sLink.concat('Vinh.xml');break;
case 6: sLink = sLink.concat('Danang.xml');break;
case 7: sLink = sLink.concat('Nhatrang.xml');break;
case 8: sLink = sLink.concat('Pleicu.xml');break;
case 9: sLink = sLink.concat('HCM.xml');break;
default: sLink = sLink.concat('Hanoi.xml');break;
}
AjaxRequest.get(
{
'url':sLink
,'onSuccess':function(req){
var vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather;
vAdImg = req.respon***ML.getElementsByTagName('AdImg').item (0).firstChild.nodeValue;
vAdImg1 = req.respon***ML.getElementsByTagName('AdImg1').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg2'). item(0).firstChild != null)
vAdImg2 = req.respon***ML.getElementsByTagName('AdImg2').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg3'). item(0).firstChild != null)
vAdImg3 = req.respon***ML.getElementsByTagName('AdImg3').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg4'). item(0).firstChild != null)
vAdImg4 = req.respon***ML.getElementsByTagName('AdImg4').ite m(0).firstChild.nodeValue;
if(req.respon***ML.getElementsByTagName('AdImg5'). item(0).firstChild != null)
vAdImg5 = req.respon***ML.getElementsByTagName('AdImg5').ite m(0).firstChild.nodeValue;
vWeather = req.respon***ML.getElementsByTagName('Weather').it em(0).firstChild.nodeValue;
GetWeatherBox(vAdImg, vAdImg1, vAdImg2, vAdImg3, vAdImg4, vAdImg5, vWeather);
}
,'onError':function(req){}
}
)
}
function GetWeatherBox(vImg, vImg1, vImg2, vImg3, vImg4, vImg5, vWeather){
var sHTML = ';
sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg).concat('" class="img-weather" alt="" /> ');
sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg1).concat('" class="img-weather" alt="" />');
if(vImg2!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg2).concat('" class="img-weather" alt="" />');
if(vImg3!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg3).concat('" class="img-weather" alt="" />');
if(vImg4!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg4).concat('" class="img-weather" alt="" />');
if(vImg5!=null) sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/').concat(vImg5).concat('" class="img-weather" alt="" />');
sHTML = sHTML.concat('<img src="http://www.vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" />');
gmobj('img-Do').innerHTML = sHTML;
gmobj('txt-Weather').innerHTML = vWeather;
}
function gmobj(o)
{
if(document.getElementById){ m=document.getElementById(o); }
else if(document.all){ m=document.all[o]; }
else if(document.layers){ m=document[o]; }
return m;
}
</script>
</head>
<body>
<form id="frmWeather" method="post" action="#">
<p>
<select id="cboWeather" class="slt-weather" onchange="ShowWeatherBox(this.value);">
<option value="1">Sơn La</option>
<option value="3">Hải Phòng</option>
<option value="4" selected="selected">Hà Nội</option>
<option value="5">Vinh</option>
<option value="6">Đà Nẵng</option>
<option value="7">Nha Trang</option>
<option value="8">Pleiku</option>
<option value="9">TP HCM</option>
</select>
</p>
<p id="img-Do"><img src="http://www.vnexpress.net/Images/Weather/i_nhieumay.gif" class="img-weather" alt="" /> <img src="http://www.vnexpress.net/Images/Weather/2.gif" class="img-weather" alt="" /><img src="http://www.vnexpress.net/Images/Weather/6.gif" class="img-weather" alt="" /><img src="http://www.vnexpress.net/Images/Weather/c.gif" class="img-weather" alt="" /></p>
<p id="txt-Weather"><b>Không mưa</b><br>Độ ẩm 91%<br>Lặng gió</p>
<script type="text/javascript" language="javascript">ShowWeatherBox(4);</script>
</form>
</body>
</html>
Bài liên quan
Minh co chay thu nhung cung dung tro tro, chi hien mot cai thoi tiet.
Ban co the dung thu cai nay, no bao gom: thoi tiet + ty gia
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
function get_weather() {
$content = file_get_contents('http://www.nchmf.gov.vn/website/vi-VN/43/Default.aspx');
$strStart = '<!-- Begin Display content -->';
$strEnd = '<TD class="thoitiet_rightbox_ver"></TD>';
$posStart = strpos($content, $strStart );
$posEnd = strpos($content, $strEnd);
if(false === $posStart ) {
return '';
}
else {
$html = substr($content, $posStart , ($posEnd - $posStart ));
return strip_tags($html , '<table><tr><td><img>');
}
}
echo get_weather();
?>
<br><br><br>
<?php
function get_exchange() {
$content = file_get_contents('http://www.agribanksaigon.com.vn/index.php');
$strStart = '<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table3" bordercolor="#DFE7EC" >';
$strEnd = '<marquee scrolldelay="25" height="220" truespeed="truespeed" scrollamount="1" onmouseover="stop()" onmouseout="start()" valign="middle" direction="up">';
$posStart = strpos($content, $strStart );
$posEnd = strpos($content, $strEnd);
if(false === $posStart ) {
return '';
}
else {
$html = substr($content, $posStart , ($posEnd - $posStart ));
return strip_tags($html , '<table><tr><td>');
}
}
echo get_exchange();
?>
</body>
</html>
nhưng đây mình muốn lấy cái thông tin của thằng vnexpress.net, mình bị lỗi cái đoạn ajax ở trên, nó cứ báo lỗi ở chỗ này
req.xmlHttpRequest.open(req.method,req.url,req.asy nc);
nhưng lạ 1 cái là chạy trên máy đơn tức chạy theo đường dẫn vật lý là: c:\\a.html thì chạy bình thường (chạy trên IE)
còn nếu tống lên host hoặc chạy bằng localhost thì coi như toi, ko chạy được,
việc kiểm tra chạy được hay ko thì các bạn thử rồi kích chọn các tỉnh thành trong ô combobox, thời tiết ko thay đổi
Rất mong các bác nào giỏi ajax xử lý hộ em đoạn trên cái, em xin cám ơn
Firefox ngăn không cho phép bạn làm như vậy vì lý do bảo mật. Nếu 2 phần (file chứa javascript và file dữ liệu) cùng domain thì được, nhưng khác domain thì không được.
Muốn làm được như vậy thì bạn phải làm khác đi một chút, firefox sẽ hiển thị hộp thoại để người sử dụng trả lời là có chấp nhận cho code của bạn làm điều đó không.
để tìm hiểu thêm về vấn đề này, bạn hãy search từ ajax cross-domain firefox.
FF không cho phép dùng javascript để lấy nội dung từ server này sang server khác vì lý do an ninh.
Chỉ có cách kết hợp với ngôn ngữ server (PHP hoặc asp.net). Dùng JS gọi 1 trang ở chính server mình, trang này sẽ đọc nội dung của trang kia và trả về cho JS xử lý.