This article provides two asynchronous calls to the weather instance code. One is to use js ajax for asynchronous calls, and the other is to use jquery ajax for asynchronous calls.
This article provides two asynchronous calls to the weather instance code. One is to use js ajax for asynchronous calls, and the other is to use jquery ajax for asynchronous calls.
<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<Html xmlns = "http://www.bKjia. c0m/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Title> jquery js asynchronously calls the weather instance Code </title>
<Script language = "webpage effect">
// Js asynchronously calls the weather
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.exe cscript) window.exe cscript (xh. responsetext );
Else eval. call (window, xh. responsetext );
Eval (callback )();
}
}
Xh. send ('');
}
// Jquery asynchronously calls the weather
$. 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 + '& nbsp; ' + '& nbsp; & nbsp;' + result. weatherinfo. weather1 + '& nbsp;' + result. weatherinfo. temp1 );
}
});
Method 3
Function page_init (){
Try {
$. Get ("asp tutorial 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 );
Response ('{persons'{.html (response. msg );
Return;
}
}
Call method:
$ (Document). ready (
Function (){
Page_init ();
});
</Script>
</Head>
<Body>
</Body>
</Html>