Two asynchronous calls to the weather instance code

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.