code thoi tiet

2
CODE THOI TIET – VNEXPRESS (PHP – XML - AJAX) I – Form hiện danh sách địa điểm: blocks/formThoiTiet.php <table width="100%" border="1"> <tr> <td> <label> <select name="danhsach" id="danhsach"> <option value="http://vnexpress.net/ListFile/Weather/HCM.xml">Ho Chi Minh</option> <option value="http://vnexpress.net/ListFile/Weather/Sonla.xml"> Son La</option> <option value="http://vnexpress.net/ListFile/Weather/Viettri.xml ">Viet Tri</option> <option value="http://vnexpress.net/ListFile/Weather/Haiphong.xm l">Hai Phong</option> <option value="http://vnexpress.net/ListFile/Weather/Hanoi.xml"> Ha Noi</option> <option value="http://vnexpress.net/ListFile/Weather/Vinh.xml">V inh</option> <option value="http://vnexpress.net/ListFile/Weather/Danang.xml" >Da Nang</option> <option value="http://vnexpress.net/ListFile/Weather/Nhatrang.xm l">Nha Trang</option> <option value="http://vnexpress.net/ListFile/Weather/Pleicu.xml" >Pleicu</option> </select> </label> </td> </tr> <tr> <td id="kq_thoitiet">&nbsp;</td> </tr> </table> II – Viết code đọc file xml thời tiết của vnexpress (thoitiet.php) $url = $_GET["url"]; $dom = new DOMDocument("1.0", "UTF8"); $dom->load($url);

Upload: smile

Post on 15-Nov-2015

10 views

Category:

Documents


2 download

TRANSCRIPT

CODE THOI TIET VNEXPRESS

CODE THOI TIET VNEXPRESS

(PHP XML - AJAX)

I Form hin danh sch a im:blocks/formThoiTiet.php

HoChiMinh SonLa VietTri HaiPhong HaNoi Vinh DaNang NhaTrang Pleicu

II Vit code c file xml thi tit ca vnexpress (thoitiet.php)$url=$_GET["url"]; $dom=newDOMDocument("1.0","UTF8"); $dom->load($url);

$AdImg=$dom->getElementsByTagName("AdImg")->item(0)->nodeValue; $AdImg1=$dom->getElementsByTagName("AdImg1")->item(0)->nodeValue; $AdImg2=$dom->getElementsByTagName("AdImg2")->item(0)->nodeValue; $Weather=$dom->getElementsByTagName("Weather")->item(0)->nodeValue;

echo"
$Weather ";III Vit code ajax trong file index.php gi d liu t thoitiet.php vo formthoitiet.php:

(Vit code trn cp gi hng)

$(document).ready(function(){

var url = $("#danhsach").val();

$.get("thoitiet.php", {url:url}, function(data){

$("#kq_thoitiet").html(data);

});

$("#danhsach").change(function(){

var url = $(this).val();

$.get("thoitiet.php", {url:url}, function(data){

$("#kq_thoitiet").html(data);

});

});

});