菜单

二款异步调用气候实例代码

2019年8月17日 - JavaScript

http://www.bkjia.com/jQuery/449347.htmlwww.bkjia.comtruehttp://www.bkjia.com/jQuery/449347.htmlTechArticle本文章提供二款异步调用天气实例代码一款是利用js
ajax异步调用另一种是利用jquery ajax 异步调用哦。
本小说提供二款异步调用气候实例代码…

<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en”
http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"&gt;
<html xmlns=”http://www.bKjia.c0m/1999/xhtml"&gt;
<head>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″
/>
<title>jquery js 异步调用天气实例代码</title>
<script language=”网页特效”>
//js异步调用天气
function getjsfile(url, callback){
var xh = window.xmlhttprequest ? new xmlhttprequest : new
activexobject(‘msxml2.xmlhttp’);
xh.open(‘get’,url,true);
xh.onreadystatechange = function(){
if(xh.readystate == 4 && xh.status == 200){
if(window.execscript) window.execscript(xh.responsetext);
else eval.call(window, xh.responsetext);
eval(callback)();
}
}
xh.send(”);
}
//jquery异步调用天气

$.ajax({type:”get”, url:
http://m.weather.com.cn/data/101210401.html“, datatype: “html”,
success: function(json){
alert(json);
var t = ‘(‘+json+’)’;
alert(t);
var result = eval(t);
//var result = eval(“{” + json + “}”);
//alert(json.responsetext);
alert(result);
$(“#weather”).append(result.weatherinfo.city+’ <img
src=”http://m.weather.com.cn/img/c'+result.weatherinfo.img1+'.gif"/&gt;'+'&nbsp;&lt;img
src=”http://m.weather.com.cn/img/c'+result.weatherinfo.img2+'.gif"/&gt;&nbsp;'+result.weatherinfo.weather1+'&nbsp;'+
result.weatherinfo.temp1);
}
});

方法三

function page_init() {
            try {
               
$.get(“asp教程x?cam_id=novell20100608&msg={count”>http://fff.ff.com/responsevalue.aspx?cam\_id=novell20100608&msg={count}“,
null, getcallback, ‘json’);
            } catch (e) {

            }

        }
        function getcallback(response) {
            if (typeof (response) != “object”) {
                $(‘#persons’).html(‘0’);
                return false;
            }
            if (response.error == 1) {
                //alert(response.msg);
                $(‘#persons’).html(response.msg);
                return;
            }

        }

调用方法:

$(document).ready(
function() {
      page_init();
});

</script>
</head>

<body>
</body>
</html>

本小说提供二款异步调用天气实例代码一款是接纳js
ajax异步调用另一种是采纳jquery ajax 异步调用哦。

本小说提供二款异步调用天气实例代码一款是使用js
ajax异步调用另一种是应用jquery ajax 异步调用哦。

 

http://www.bkjia.com/jQuery/449415.htmlwww.bkjia.comtruehttp://www.bkjia.com/jQuery/449415.htmlTechArticle本文章提供二款异步调用天气实例代码一款是利用js
ajax异步调用另一种是行使jquery ajax 异步调用哦。
本文章提供二款异步调用天气实例代码…

<!doctype html public “-//w3c//dtd xhtml 1.0 transitional//en”
http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"&gt;
<html xmlns=”http://www.bKjia.c0m/1999/xhtml"&gt;
<head>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″
/>
<title>jquery js 异步调用天气实例代码</title>
<script language=”网页特效”>
//js异步调用天气
function getjsfile(url, callback){
var xh = window.xmlhttprequest ? new xmlhttprequest : new
activexobject(‘msxml2.xmlhttp’);
xh.open(‘get’,url,true);
xh.onreadystatechange = function(){
if(xh.readystate == 4 && xh.status == 200){
if(window.execscript) window.execscript(xh.responsetext);
else eval.call(window, xh.responsetext);
eval(callback)();
}
}
xh.send(”);
}
//jquery异步调用气候

$.ajax({type:”get”, url:
http://m.weather.com.cn/data/101210401.html“, datatype: “html”,
success: function(json){
alert(json);
var t = ‘(‘+json+’)’;
alert(t);
var result = eval(t);
//var result = eval(“{” + json + “}”);
//alert(json.responsetext);
alert(result);
$(“#weather”).append(result.weatherinfo.city+’ <img
src=”http://m.weather.com.cn/img/c'+result.weatherinfo.img1+'.gif"/&gt;'+'&nbsp;&lt;img
src=”http://m.weather.com.cn/img/c'+result.weatherinfo.img2+'.gif"/&gt;&nbsp;'+result.weatherinfo.weather1+'&nbsp;'+
result.weatherinfo.temp1);
}
});

方法三

function page_init() {
            try {
               
$.get(“asp教程x?cam_id=novell20100608&msg={count”>http://fff.ff.com/responsevalue.aspx?cam\_id=novell20100608&msg={count}“,
null, getcallback, ‘json’);
            } catch (e) {

            }

        }
        function getcallback(response) {
            if (typeof (response) != “object”) {
                $(‘#persons’).html(‘0’);
                return false;
            }
            if (response.error == 1) {
                //alert(response.msg);
                $(‘#persons’).html(response.msg);
                return;
            }

        }

调用方法:

$(document).ready(
function() {
      page_init();
});

</script>
</head>

<body>
</body>
</html>

本作品提供二款异步调用天气实例代码一款是行使js
ajax异步调用另一种是选择jquery ajax 异步调用哦。

本小说提供二款异步调用天气实例代码一款是选用js
ajax异步调用另一种是运用jquery ajax 异步调用哦。

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图