Html+javascript+soap Get WebService Free weather forecast information

Source: Internet
Author: User
Tags soap

Turn from: http://blog.163.com/[email protected]/blog/static/8004881020118303318687/

First and foremost is the free weather source on the Internet:
Http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
Open this web page with a browser, you can see a brief description of the address through soap to send a GET or POST request, to get the desired regional weather information, updated every 2.5 hours.
Second, write a simple HTML page and add a JS function inside to access the above page, submit the request, the simple HTML page is as follows:
<script type= "Text/javascript" >
function Get () {
>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>
}
</script>
<body onload= "Get ()" >
<input type=text id= "data" name= "SD" >
</body>
Write the JS function in a simple page, and the contents of this get function can be executed when the page is opened by the browser. Here, the function of the GET function is to create the SOAP header, send the request, return the request, process the returned XML
Third, add access to the link address:
var url= "Http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
Iv. add a variable that acts as a city:
var city = "Beijing";
Re-create the sent packets:
var data = ' <?xml version= ' 1.0 "encoding=" UTF-8 "?>";
data = Data + ' <soap:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/ 2001/xmlschema "xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/">";
data = data + ' <soap:Body> ';
data = Data + ' <getweatherbycityname xmlns= ' http://WebXml.com.cn/> ';
data = data + ' <theCityName> ' +city+ ' </theCityName> ';
data = data + ' </getWeatherbyCityName> ';
data = data + ' </soap:Body> ';
data = data + ' </soap:Envelope> ';
VI. Create a new XMLHTTP object:
if (window. ActiveXObject)
{
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
else if (window. XMLHttpRequest)
{
Xmlhttp=new XMLHttpRequest ();
}
VII, add XMLHTTP, send headers, and send the package.
Xmlhttp.open ("POST", URL, false);
Xmlhttp.setrequestheader ("Content-type", "text/xml;charset=utf-8");
Xmlhttp.setrequestheader ("SOAPAction", "http://WebXml.com.cn/getWeatherbyCityName");
Xmlhttp.send (data);
Eighth, deal with the content returned by XMLHTTP, here use a 23-bit array to accept the string,
var xmldoc = Xmlhttp.responsexml;
var weather = new Array (23);
for (i=0;i<23;i++)
Weather[i] = xmlDoc.documentElement.childNodes (0). ChildNodes (0). ChildNodes (0). ChildNodes (i). text;
Finally, the completion of this string, want to deal with how to deal with, can alert, can document.write, with you. I'll alert you here.
Alert (weather);
It's done! Of course, this code would like to have a lot of incompatible problems, such as currently incompatible with Firefox,

Html+javascript+soap Get WebService Free weather forecast information

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.